﻿
//===============================================================================
//	Player.h
//	用户类
//===============================================================================

//#include <locale>
//#include <string>
//#include <codecvt>
//#include <wchar.h>

#include <boost/lexical_cast.hpp>
#include "Player.h"

#include "ManagerHelper.h"

#include "PlayerDataStruct.inl"
//#include "CellSpacePartition.h"

#include "PlayerCommon.h"

#include "../share/user_define.h"

#include "../share/MessageDef.h"

#include "Fixed1024.h"
#include "PlayerTemporaryDataDefinition.h"

#include "script_define.h"

//#include "../share/StringFactory.h"
#include "ConstantDefine.h"

#include "FightProperty.h"
//-------------------------------------------------------------------------------
#include "COpenMissionDialog.h"
#include "CAskMissionComplete.h"
#include "CAskMissionList.h"
#include "COpenRewardDialogue.h"
#include "CNoticeCommon.h"
#include "CGeneralJsonStringRet.h"
#include "CPing.h"
#include "CEnterScene.h"
#include "CLeaveScene.h"
#include "CPlayerAttack.h"
#include "CUpdatePlayerInfo.h"
#include "CLoseBlood.h"
#include "CSomeoneDead.h"
#include "CAskMissionList.h"
#include "CAskMissionComplete.h"
#include "CNoticeCommonEx.h"
#include "CTitleList.h"
#include "CTitleTakeOffOrWear.h"
#include "CAskMissionBoxInfo.h"

#include "CAskOfferRewardMissionList.h"
#include "CUpdateMissionItemInfo.h"

#include "CGuideInfo.h"
#include "CUpdateSpecifiedBufferPart.h"
#include "CUIAction.h"
#include "CWildDigOperation.h"
#include "CFixed1024Info.h"
#include "CServerInitFinished.h"
#include "CGetRankListInfo.h"
#include "CAskDailyMissionList.h"
#include "CPlayerLoadSceneFinished.h"
#include "CErrMessage.h"
#include "CRelayMessage.h"
#include "CPlayerMove.h"
#include "CKick.h"
#include "CTwGroupIdNotifyRet.h"
#include "CZeroBlood.h"
#include "CChatMessageGeneralPush.h"
#include "CChatMessageGeneralRet.h"
#include "CChatToFriendMessageRet.h"
#include "CChatFriendMessageGeneralPush.h"

#include "LuaScriptManager.h"
#include "GameServer.h"
#include "../share/proxyclient_service.h"
#include "MapSlot.h"
#include "scene_logic.h"
#include "../share/time_module.h"
#include "../share/base.h"
#include "playerinfo_mgr.h"



//#include "GDGeneralMessage.h"
extern std::shared_ptr<LuaScriptManager> g_lua_script_manager;

#define detail_size  1024 * 2048
static char detail_data[detail_size] = { 0 };

//-------------------------------------------------------------------------------
void Player::createSocketMessage(void)
{
	_safe_guard_begin;

	m_ping = dynamic_cast<CPing*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, player_ping_ret));
	_safe_check(m_ping);

	m_enter_scene = dynamic_cast<CEnterScene*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_player_enter_scene));
	_safe_check(m_enter_scene);

	m_leave_scene = dynamic_cast<CLeaveScene*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_player_leave_scene));
	_safe_check(m_leave_scene);

	m_player_attack = dynamic_cast<CPlayerAttack*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_player_attack_ret));
	_safe_check(m_player_attack);

	m_update_player_info = dynamic_cast<CUpdatePlayerInfo*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_update_player_info));
	_safe_check(m_update_player_info);

	m_lose_blood = dynamic_cast<CLoseBlood*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_lose_blood_ret));
	_safe_check(m_lose_blood);

	m_someone_dead = dynamic_cast<CSomeoneDead*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_someone_dead_ret));
	_safe_check(m_someone_dead);

	// 
	//m_PlayerRegisterRet = static_cast<CPlayerRegisterRet*>(
	//	MsgFactoryPtr->CreateMessage(m_socket_id, login_create_player_ret));
	//_safe_check(m_PlayerRegisterRet);

	//m_PlayerLoginRet = static_cast<CPlayerLoginRet*>(
	//	MsgFactoryPtr->CreateMessage(m_socket_id, login_player_login_ret));
	//_safe_check(m_PlayerLoginRet);

	//m_CheckAccountRet = static_cast<CCheckAccountRet*>(
	//	MsgFactoryPtr->CreateMessage(m_socket_id, login_check_account_ret));
	//_safe_check(m_CheckAccountRet);

	m_GeneralJsonStringRet = dynamic_cast<CGeneralJsonStringRet*>(
		MsgFactoryPtr->CreateMessage(m_socket_id, common_backpack_list_ret));
	_safe_check(m_GeneralJsonStringRet);

	m_tw_group_id_notify = dynamic_cast<CTwGroupIdNotifyRet*>(
		MsgFactoryPtr->CreateMessage(m_socket_id, wt_group_id_changed_push));
	_safe_check(m_tw_group_id_notify);

	m_ask_mission_list = dynamic_cast<CAskMissionList*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_mission_list_ret));
	_safe_check(m_ask_mission_list);

	m_ask_mission_list_complete = dynamic_cast<CAskMissionComplete*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_mission_complete_list_ret));
	_safe_check(m_ask_mission_list_complete);

	m_open_mission_dlg = dynamic_cast<COpenMissionDialog*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_open_mission_dialog_ret));
	_safe_check(m_open_mission_dlg);

	m_notice_common = dynamic_cast<CNoticeCommon*>(
		MsgFactoryPtr->CreateMessage(m_socket_id, common_notice_common_ret));
	_safe_check(m_notice_common);

	m_open_reward_dlg = dynamic_cast<COpenRewardDialogue*>(
		MsgFactoryPtr->CreateMessage(m_socket_id, common_notice_reward_dialogue_common_ret));
	_safe_check(m_open_reward_dlg);

	m_notice_common_ex = dynamic_cast<CNoticeCommonEx*>(
		MsgFactoryPtr->CreateMessage(m_socket_id, common_notice_common_ex_ret));
	_safe_check(m_notice_common_ex);

	m_title_list = dynamic_cast<CTitleList*>(
		MsgFactoryPtr->CreateMessage(m_socket_id, common_title_list_ret));
	_safe_check(m_title_list);

	m_title_takeoff_wear = dynamic_cast<CTitleTakeOffOrWear*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_title_wear_or_takeoff_ret));
	_safe_check(m_title_takeoff_wear);

	m_mission_box_info = dynamic_cast<CAskMissionBoxInfo*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_mission_box_info_ret));
	_safe_check(m_mission_box_info);

	m_offer_reward_mission_list = dynamic_cast<CAskOfferRewardMissionList*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_offer_reward_mission_list_ret));
	_safe_check(m_offer_reward_mission_list);


	m_update_mission_item_ret = dynamic_cast<CUpdateMissionItemInfo*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_update_mission_item_info_ret));
	_safe_check(m_update_mission_item_ret);

	m_guide_info = dynamic_cast<CGuideInfo*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_player_guide_info_ret));
	_safe_check(m_guide_info);

	m_update_specified_buffer_part = dynamic_cast<CUpdateSpecifiedBufferPart*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_player_buffer_specified_part));
	_safe_check(m_update_specified_buffer_part);

	m_ui_action = dynamic_cast<CUIAction*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_player_manipulate_specified_UI));
	_safe_check(m_ui_action);

	m_wild_dig_operation = dynamic_cast<CWildDigOperation*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_wild_dig_operation_ret));
	_safe_check(m_wild_dig_operation);

	m_fixed_1024_info = dynamic_cast<CFixed1024Info*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_player_Fixed_info_ret));
	_safe_check(m_fixed_1024_info);

	m_server_init_finished = dynamic_cast<CServerInitFinished*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_player_data_init_finished));
	_safe_check(m_server_init_finished);

	//m_get_rank_list = dynamic_cast<CGetRankListInfo*>(
	//	MsgFactoryPtr->CreateMessage(this->m_socket_id, common_ranklist_ret));
	//_safe_check(m_get_rank_list);

	m_ask_daily_mission_list_ret = dynamic_cast<CAskDailyMissionList*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_ask_daily_mission_ret));
	_safe_check(m_ask_daily_mission_list_ret);

	//m_player_load_scene_finished = dynamic_cast<CPlayerLoadSceneFinished*>(
	//	MsgFactoryPtr->CreateMessage(this->m_socket_id, c_player_load_scene_finished));
	//_safe_check(m_player_load_scene_finished);

	m_player_err_ret = dynamic_cast<CErrMessage*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, err_message_common_ret));
	_safe_check(m_player_err_ret);

	m_relay_message = dynamic_cast<CRelayMessage*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, player_relay_ret));
	_safe_check(m_relay_message);
	
	//m_gd_general_message_notify = dynamic_cast<GDGeneralMessage*>(
	//	MsgFactoryPtr->CreateMessage(this->m_socket_id, db_general_message));
	//_safe_check(m_gd_general_message_notify);

	m_player_move = dynamic_cast<CPlayerMove*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_player_move));
	_safe_check(m_player_move);

	m_kick = dynamic_cast<CKick*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, kick_player_client_notify));
	_safe_check(m_kick);

	/*关闭
	m_ask_branch_mission_list_ret = dynamic_cast<CAskBranchMissionList*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_ask_branch_mission_ret));
	_safe_check(m_ask_branch_mission_list_ret);
	*/

	m_target_zero_blood_notify = dynamic_cast<CZeroBlood*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, c_target_zero_blood_push));
	_safe_check(m_target_zero_blood_notify);
	
	m_chat_message_general_push = dynamic_cast<CChatMessageGeneralPush*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_server_chat_msg_notify_push));
	_safe_check(m_chat_message_general_push);

	m_chat_message_general_ret = dynamic_cast<CChatMessageGeneralRet*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, player_chat_message_ret));
	_safe_check(m_chat_message_general_ret);

	m_chat_firend_message_ret = dynamic_cast<CChatToFriendMessageRet*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, player_friend_chat_message_ret));
	_safe_check(m_chat_firend_message_ret);

	m_chat_friend_message_push = dynamic_cast<CChatFriendMessageGeneralPush*>(
		MsgFactoryPtr->CreateMessage(this->m_socket_id, common_server_chat_friend_msg_notify_push));
	_safe_check(m_chat_friend_message_push);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::deleteSocketMessage(void)
{
	_safe_guard_begin;

	MsgFactoryPtr->DeleteMessage(m_target_zero_blood_notify);
	//MsgFactoryPtr->DeleteMessage(m_gd_general_message_notify);
	/*关闭
	MsgFactoryPtr->DeleteMessage(m_ask_branch_mission_list_ret);
	*/
	MsgFactoryPtr->DeleteMessage(m_kick);
	MsgFactoryPtr->DeleteMessage(m_player_move);
	MsgFactoryPtr->DeleteMessage(m_relay_message);
	MsgFactoryPtr->DeleteMessage(m_player_err_ret);
	//MsgFactoryPtr->DeleteMessage(m_player_load_scene_finished);
	MsgFactoryPtr->DeleteMessage(m_ask_daily_mission_list_ret);
//	MsgFactoryPtr->DeleteMessage(m_get_rank_list);
	MsgFactoryPtr->DeleteMessage(m_server_init_finished);
	MsgFactoryPtr->DeleteMessage(m_fixed_1024_info);
	MsgFactoryPtr->DeleteMessage(m_wild_dig_operation);
	MsgFactoryPtr->DeleteMessage(m_ui_action);
	MsgFactoryPtr->DeleteMessage(m_update_specified_buffer_part);
	MsgFactoryPtr->DeleteMessage(m_guide_info);
	MsgFactoryPtr->DeleteMessage(m_update_mission_item_ret);

	MsgFactoryPtr->DeleteMessage(m_offer_reward_mission_list);
	MsgFactoryPtr->DeleteMessage(m_mission_box_info);
	MsgFactoryPtr->DeleteMessage(m_title_takeoff_wear);
	MsgFactoryPtr->DeleteMessage(m_title_list);
	MsgFactoryPtr->DeleteMessage(m_notice_common_ex);
	MsgFactoryPtr->DeleteMessage(m_open_reward_dlg);
	MsgFactoryPtr->DeleteMessage(m_notice_common);
	MsgFactoryPtr->DeleteMessage(m_open_mission_dlg);
	MsgFactoryPtr->DeleteMessage(m_ask_mission_list_complete);
	MsgFactoryPtr->DeleteMessage(m_ask_mission_list);
	MsgFactoryPtr->DeleteMessage(m_tw_group_id_notify);
	MsgFactoryPtr->DeleteMessage(m_GeneralJsonStringRet);
	MsgFactoryPtr->DeleteMessage(m_someone_dead);
	MsgFactoryPtr->DeleteMessage(m_lose_blood);
	//MsgFactoryPtr->DeleteMessage(m_notify);
	MsgFactoryPtr->DeleteMessage(m_update_player_info);
	MsgFactoryPtr->DeleteMessage(m_player_attack);
	MsgFactoryPtr->DeleteMessage(m_leave_scene);
	MsgFactoryPtr->DeleteMessage(m_enter_scene);
	MsgFactoryPtr->DeleteMessage(m_ping);
	MsgFactoryPtr->DeleteMessage(m_chat_message_general_push);
	MsgFactoryPtr->DeleteMessage(m_chat_message_general_ret);
	MsgFactoryPtr->DeleteMessage(m_chat_firend_message_ret);
	MsgFactoryPtr->DeleteMessage(m_chat_friend_message_push);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::updatePlayerInfo(void)
{
	_safe_guard_begin;

	uint32_t _flag = GetUpdateInfoFlag();
	if (_flag > 0)
	{
		ClearUpdateInfoFlag();

		m_update_player_info->Clear();
		m_update_player_info->SetPlayer(this, _flag);

		// 同步玩家信息给map
		SyncPlayer2MapByFlag(_flag);
	}

	_flag = 0;
	_flag = GetUpdateInfoMyFlag();
	if (_flag > 0)
	{
		ClearUpdateInfoMyFlag();

		m_update_player_info->Clear();
		m_update_player_info->SetPlayer(this, _flag);

		//	发给自己
		std::string send_up = m_update_player_info->GetSendStringList();
		SendToClient(&send_up,
			m_update_player_info->GetProtocolNumber());
	}


	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::clearPlayerInfo(void)
{
	_safe_guard_begin;
	// --


	memset(m_Name, 0, 32);				// 昵称
	memset(m_UnionName, 0, 64);

	m_last_pos_caculate_time = 0;	//	前一次计算移动距离的时间

	m_PlayerId = 0;
	m_Account = 0;				// 帐号
	m_Area = 0;					// 所在游戏区
	m_Photo = 0;				// 头像ID
	m_PhotoFrame = 0;			// 头像框ID
	m_Exps = 0;					// 当前经验值
	m_MaxExps = 0;				// 当前最大经验值
	m_Level = 0;				// 当前等级
	m_HeroId = 0;				// 当前英雄ID
	m_Vip = 0;					// VIP等级
	m_VipExps = 0;				// VIP经验
	m_UnionId = 0;				// 工会ID
	m_UnionPosition = 0;		// 工会职位
	m_Afc = 0;					// 战队战斗力

	m_TDining = 0;
	m_Thew = 0;					// 体力

	m_OnlineReward = 0;			// 在线奖励
	m_SkillPoint = 0;			// 技能点
	m_SkillPointTime = 0;		// 技能点20点满点时间

	m_SoulDraw = 0;				// 魂匣抽奖计数
	m_GoldDraw = 0;				// 金币抽奖计数
	m_DiamondDraw = 0;			// 钻石抽奖计数
	m_ChangeName = 0;			// 修改昵称计数
	m_OnlineTime = 0;			// 在线时长
	m_MaxRank = 0;				// 角斗场最大排行
	m_BuyThew = 0;

	m_PassedTime = 0;			// heartbeat过去的时间
	m_ExpsPool = 0;				// 英雄经验池
	m_PetId = 0;				// 宠物ID
	m_MountsId = 0;				// 坐骑ID
	m_CurrHeroLevel = 1;		// 当前出阵英雄等级

	m_DefPetId = 0;				// 默认设定宠物ID
	m_DefMountsId = 0;			// 默认设定坐骑ID
	m_Newbie = 0;				// 是否新手
	m_NewbieFlag = 0;			// 1:新号注册/0:登录

	m_MaxThewTime = 0;			// 恢复至最大体力时间点

	m_update_fixed_flag = 0;	// 1024分段存储标记

	m_update_info_flag = 0;
	m_update_info_my_flag = 0;

	m_player_lua_ptr = nullptr;

	m_runtime_info->Clear();
	m_property->Clear();


	m_HeartBeatCount = 0;		// HeartBeat临时计数器

	m_RecoverThewCount = 0;
	//王昱智添加
	m_achievementLevel = 0;
	m_allServiceAchievementRanking = 0;
	update_time_ = 0;
	last_save_time_ = 0;

	m_pos_x = 0;
	m_pos_y = 0;
	m_pos_z = 0;
	_safe_guard_end;
}

void Player::recoverPlayerThew(void)
{
	_safe_guard_begin;

	uint32_t maxThew = 60;
	if (m_Level > 1)
	{
		maxThew += m_Level;
	}

	if (m_Thew < maxThew)
	{
		m_Thew += 1;

		SetUpdateInfoMyFlag(UpdatePlayerInfoType::Vitality);

		std::string _key = "thew";
		SetPlayerSomeInfoToRedisDB(_key, (int32_t)m_Thew);
	}

	_safe_guard_end;
}


//-------------------------------------------------------------------------------

#include "CCheckAccountRet.h"
#include "CPlayerRegisterRet.h"
#include "CPlayerLoginRet.h"

//-------------------------------------------------------------------------------
Player::Player(void)
	: Role()
	, m_runtime_info(new PlayerRuntimeInfo())
	, m_property(new PlayerCommon())
	//, m_branch_mission(new MissionBranch())
	, m_last_pos_caculate_time(0)
	, m_update_info_flag(0)
	, m_HerosCount(0)
	, m_Afc(0)
	, m_Level(0)
	, m_Vip(0)
	, m_ForeverCardRewardState( -1 )
	, m_continueRecharge()
	, player_link_(this)
{
	_safe_guard_begin;

	clearPlayerInfo();

	_mem_zero(m_CurTitleProperty, max_property_count);
	_mem_zero(m_TitleGetTime, max_special_title_count);

	for (uint32_t i = 0; i < max_hero_count; ++i)
	{
		m_playerHero[i].Clear();
	}

	createSocketMessage();
	connected_ = false;
	disconnect_time_ = CUR_SEC;
	m_ping_time = 0;
	update_time_ = CUR_SEC;
	m_RecoverThewCount = CUR_SEC;
	last_save_time_ = 0;
	m_socket_id = -1;
	last_pos_.Clear();
	_safe_guard_end;
}

//-------------------------------------------------------------------------------
Player::~Player(void)
{
	deleteSocketMessage();

	_safe_delete(m_property);
	_safe_delete(m_runtime_info);

	m_player_lua_ptr = nullptr;
}

//-------------------------------------------------------------------------------
void Player::Heartbeat(uint32_t passTime /*= 0*/)
{
	_safe_guard_begin;

	if (!HasData())
	{
		return;
	}

	// 心跳检查
	if (!CheckPingTime())
	{
		LOG_INFO("default","KICK PLAYER !!!! CheckPingTime kick : key=%u, account=%u, playerId=%u",
			GetKey(), GetAccount(),  GetPlayerId());
		
		CSceneLogic::GetInstance().PlayerLeaveGame(*this);
		return;
	}

	if (!PlayerInGame())
	{
		return;
	}

	time_t cur_sec = CUR_SEC;
	time_t update_time = update_time_;
	if ( update_time_ == 0 )
	{
		update_time_ = CUR_SEC;
		return;
	}
	if (cur_sec > update_time)
	{
		int32_t tmp = cur_sec - update_time;
		AddFixedValue(Fixed1024::PLAYER_ONLINE_TIME, tmp);
		AddFixedValue(Fixed1024::PLAYER_ONCE_ONLINE_TIME, tmp);
		ReduceFixedValue(Fixed1024::PLAYER_ONLINE_REWARD_LAST_TIME, tmp);

		SetOnlineTime(GetOnlineTime() + tmp);

		// 回复体力 每6分钟回复1点
		if (m_RecoverThewCount + 6 * 60 < cur_sec)
		{
			recoverPlayerThew();
			m_RecoverThewCount = cur_sec;
		}

		//检查有没有跨天;
		tm* update_tm = localtime(&update_time);
		if (NULL != update_tm)
		{
			int32_t update_month = update_tm->tm_mon;
			time_t day_time = ::common::RebuildTime(update_tm, 50000);
			time_t day_zero_time = day_time - 5 * 60 * 60;
			int32_t week_day = update_tm->tm_wday;
			if (week_day == 0)
			{
				week_day = 7;
			}
			int32_t week_time = day_time - (week_day - 1) * 24 * 60 * 60;

			if (update_time > day_time)
			{
				day_time += 24 * 60 * 60;
			}

			if (update_time > day_zero_time)
			{
				day_zero_time += 24 * 60 * 60;
			}

			if (update_time > week_time)
			{
				week_time += 7 * 24 * 60 * 60;
			}

			if (cur_sec >= day_time &&
				update_time < day_time)
			{
				//新的一天处理;
				OnNewDay();
			}
			//零点跨天

			if (cur_sec >= day_zero_time &&
				update_time < day_zero_time)
			{
				OnNewZeroDay();
			}

			if (cur_sec >= week_time &&
				update_time < week_time)
			{
				OnNewWeek();
			}

			tm* cur_tm = localtime(&cur_sec);
			if (NULL != cur_tm)
			{
				if (cur_tm->tm_mon != update_month)
				{
					OnNewMonth();
				}
			}
		}
		update_time_ = cur_sec;
	}

	_safe_guard_end;
}

void Player::TickUpdate()
{
	_safe_guard_begin;

	// 心跳检查
	if (!CheckPingTime())
	{
		LOG_INFO("default", "KICK PLAYER !!!! CheckPingTime kick : key=%u, account=%u, playerId=%u",
			GetKey(), GetAccount(), GetPlayerId());

		CSceneLogic::GetInstance().PlayerLeaveGame(*this);
		return;
	}

	if (!PlayerInGame())
	{
		return;
	}

	time_t cur_sec = CUR_SEC;
	time_t update_time = update_time_;
	if (update_time_ == 0)
	{
		update_time_ = CUR_SEC;
		return;
	}
	if (cur_sec > update_time)
	{
		int32_t tmp = cur_sec - update_time;
		AddFixedValue(Fixed1024::PLAYER_ONLINE_TIME, tmp);
		AddFixedValue(Fixed1024::PLAYER_ONCE_ONLINE_TIME, tmp);
		ReduceFixedValue(Fixed1024::PLAYER_ONLINE_REWARD_LAST_TIME, tmp);

		SetOnlineTime(GetOnlineTime() + tmp);

		// 回复体力 每6分钟回复1点
		if (m_RecoverThewCount + 6 * 60 < cur_sec)
		{
			recoverPlayerThew();
			m_RecoverThewCount = cur_sec;
		}

		//检查有没有跨天;
		tm* update_tm = localtime(&update_time);
		if (NULL != update_tm)
		{
			int32_t update_month = update_tm->tm_mon;
			time_t day_time = ::common::RebuildTime(update_tm, 50000);
			time_t day_zero_time = day_time - 5 * 60 * 60;
			int32_t week_day = update_tm->tm_wday;
			if (week_day == 0)
			{
				week_day = 7;
			}
			int32_t week_time = day_time - (week_day - 1) * 24 * 60 * 60;

			if (update_time > day_time)
			{
				day_time += 24 * 60 * 60;
			}

			if (update_time > day_zero_time)
			{
				day_zero_time += 24 * 60 * 60;
			}

			if (update_time > week_time)
			{
				week_time += 7 * 24 * 60 * 60;
			}

			if (cur_sec >= day_time &&
				update_time < day_time)
			{
				//新的一天处理;
				OnNewDay();
			}
			//零点跨天

			if (cur_sec >= day_zero_time &&
				update_time < day_zero_time)
			{
				OnNewZeroDay();
			}

			if (cur_sec >= week_time &&
				update_time < week_time)
			{
				OnNewWeek();
			}

			tm* cur_tm = localtime(&cur_sec);
			if (NULL != cur_tm)
			{
				if (cur_tm->tm_mon != update_month)
				{
					OnNewMonth();
				}
			}
		}
		update_time_ = cur_sec;
	}

	_safe_guard_end;
}


//-------------------------------------------------------------------------------
void Player::Update(uint32_t passTime /*= 0*/)
{
	_safe_guard_begin;

	if (!HasData())
	{
		return;
	}

	updatePlayerInfo();

	_safe_guard_end;
}


//-------------------------------------------------------------------------------
void Player::GetFixed1024InfoByErea(uint32_t startPos, uint32_t endPos)
{
	_safe_guard_begin;

	UIntArray<uint32_t, size_1024>* msState = GetMissionState();
	_safe_check(msState);

	m_fixed_1024_info->Clear();
	m_fixed_1024_info->SetFixed1024Info(msState, startPos, endPos);

	SendToClient(m_fixed_1024_info->GetSendString(), m_fixed_1024_info->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::Send2CEnterScene(uint32_t sceneId, double posX, double posY, double posZ)
{
	_safe_guard_begin;

	uint32_t accoutId = GetAccount();

	m_enter_scene->Clear();
	m_enter_scene->SetSceneAndPosition(sceneId, posX, posY, posZ, accoutId);

	SendToClient(m_enter_scene->GetSendString(), m_enter_scene->GetProtocolNumber());

	LOG_DEBUG("default","c_player_enter_scene to %d|%d -> sendStr: %s",
		m_Account, m_PlayerId, m_enter_scene->GetSendToServerString()->c_str());

	_safe_guard_end;

}

//-------------------------------------------------------------------------------
void Player::Send2CLevelScene(uint32_t sceneId)
{
	_safe_guard_begin;

	m_leave_scene->Clear();
	m_leave_scene->SetNewSceneId(sceneId);

	SendToClient(m_leave_scene->GetSendString(), m_leave_scene->GetProtocolNumber());

	LOG_DEBUG("default","c_player_leave_scene to %d|%d -> sendStr: %s",
		m_Account, m_PlayerId, m_leave_scene->GetSendToServerString()->c_str());

	_safe_guard_end;
}


void Player::SyncMyRedisData2Mysql()
{
	_safe_guard_begin;
	
	if ( !HasData() )
		return;

	uint32_t uPid=GetSn();
	//TODO:CXL，这里不用全部先存一遍了，直接下面的会全部存一遍
	SavePlayerFixedInfo();

	if ( nullptr==m_player_lua_ptr )
		return;

	m_player_lua_ptr->RunScriptFunction( LUA_PlayerManagerScript, LUA_SyncRedisData2Mysql, m_PlayerId, uPid );

	_safe_guard_end;
}
//-------------------------------------------------------------------------------
void Player::KickPlayerNotify(uint32_t kickType)
{
	_safe_guard_begin;

	if ( m_socket_id < 0 )
	{
		return;
	}
	//	踢人前通知
	m_kick->Clear();
	m_kick->SetKickPlayer(this->GetPlayerId(), kickType);//0:默认,1:重复登录,2:服务器关闭
	SendToClient(m_kick->GetSendToServerString(), m_kick->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::Bekilled(uint32_t whoId)
{
	_safe_guard_begin;



	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::KilledSomeone(MapElement* tar)
{
	_safe_guard_begin;

	if (
		GOT_MONSTER == tar->GetObjectType() ||
		GOT_RAND_MONSTER == tar->GetObjectType()
		)
	{
		///检查悬赏任务：杀怪脚本
		uint32_t _typeId = tar->GetTypeId();//场景元素类型id
		//uint32_t _typeId = tar->GetKey();//地图元素识别id

		if (nullptr == m_player_lua_ptr)
		{
			return;
		}
		_safe_check(m_player_lua_ptr != nullptr);

		uint32_t _usrPosId = GetSn();
		if (m_player_lua_ptr->TryLock())
		{
			m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardKillMonsterScript
				, LUA_KillMonster, _usrPosId, _typeId);
		}
		else
		{
			m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardKillMonsterScript
				, LUA_KillMonster, _usrPosId, _typeId);
			LOG_ERROR("default","TryLock FALSE! KilledSomeone 1");
		}

		///检查主线杀怪/-掉落任务
		KillMonsterMainMission(_typeId);
	}
	else if (GOT_PLAYER == tar->GetObjectType())
	{
		if (nullptr == m_player_lua_ptr)
		{
			return;
		}
		///悬赏任务：杀人脚本
		_safe_check(m_player_lua_ptr != nullptr);

		uint32_t _usrPosId = GetSn();
		if (m_player_lua_ptr->TryLock())
		{
			m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardKillPlayerScript
				, LUA_KillPlayer, (int32_t)_usrPosId);
		}
		else
		{
			m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardKillPlayerScript
				, LUA_KillPlayer, (int32_t)_usrPosId);
			LOG_ERROR("default","TryLock FALSE! KilledSomeone 2");
		}
	}

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::TargetZeroBloodNotify(uint32_t tarId)
{
	_safe_guard_begin;

	_safe_check(m_target_zero_blood_notify);
	m_target_zero_blood_notify->Clear();
	m_target_zero_blood_notify->SetParameter(tarId);

	SendToClient(m_target_zero_blood_notify->GetSendToServerString(), m_target_zero_blood_notify->GetProtocolNumber());

	_safe_guard_end;
}
//-------------------------------------------------------------------------------
uint32_t Player::GetSocketId(void)
{
	_safe_guard_begin;

	return m_socket_id;

	_safe_guard_end;

}

//-------------------------------------------------------------------------------
void Player::SetSocketId(int32_t socketId)
{
	_safe_guard_begin;

	m_socket_id = socketId;

	_safe_guard_end;
}


//-------------------------------------------------------------------------------
void Player::SetFixedBitValue(uint16_t idx, uint16_t start, uint16_t size, uint32_t val)
{
	_safe_guard_begin;

	if (0 > idx || idx >= size_1024)
	{
		return;
	}

	m_Buffer.SetBitValue(idx, start, size, val);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
int32_t Player::GetFixedBitValue(uint16_t idx, uint16_t start, uint16_t size)
{
	_safe_guard_begin;

	if (0 > idx || idx >= size_1024)
	{
		return 0;
	}

	return m_Buffer.GetBitValue(idx, start, size);

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
void Player::SetFixedValue(uint16_t idx, uint32_t val)
{
	_safe_guard_begin;

	if (0 > idx || idx >= size_1024)
	{
		return;
	}

	//test836
	if (836 == idx)
	{
		int _pause = 0;
		std::cout << _pause << std::endl;
	}
	//!test836

	m_Buffer.SetValue(idx, val);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
int32_t Player::GetFixedValue(uint16_t idx)
{
	_safe_guard_begin;

	if (0 > idx || idx >= size_1024)
	{
		return 0;
	}

	return m_Buffer.GetValue(idx);

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
void Player::AddFixedValue(uint16_t idx, uint32_t val)
{
	_safe_guard_begin;

	if (0 > idx || idx >= size_1024)
	{
		return;
	}

	uint32_t _val = m_Buffer.GetValue(idx);
	_val += val;

	m_Buffer.SetValue(idx, _val);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::ReduceFixedValue(uint16_t idx, uint32_t val)
{
	_safe_guard_begin;

	if (0 > idx || idx >= size_1024)
	{
		return;
	}

	uint32_t _val = m_Buffer.GetValue(idx);
	if (_val == 0)
	{
		return;
	}

	if (_val > val)
	{
		_val -= val;
	}
	else
	{
		_val = 0;
	}

	m_Buffer.SetValue(idx, _val);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
uint32_t Player::GetFixedPosValueByIndex(uint16_t idx)
{
	_safe_guard_begin;

	if (0 > idx || idx >= size_1024)
	{
		return 0;
	}

	//！慎用
	//uint32_t _baseVal = size_1024 / fixed_part_pos_count;
	//return idx / _baseVal + 1;

	return (idx >> 6) + 1;
	
	_safe_guard_end;

	return 0;
}


//-------------------------------------------------------------------------------
void Player::SendToClient(std::string* str, uint32_t msgId)
{
	_safe_guard_begin;

	if (str == NULL)
	{
		LOG_ERROR("default","send to client msg is null");
		return;
	}

	if (m_socket_id >= 0)
	{
		LOG_DEBUG("default","SendToClient Player: %d, msgId: 0x%04X(%u), len %d", this->GetPlayerId(), msgId, msgId, str->size());

		GameServer::GetInstance().client_msg_dispatch(*str, m_socket_id, msgId);
	}
	else
	{
		LOG_ERROR("default","SendToClient Player: %d, m_socket_id is %d, can't send %d ...", GetPlayerId(), m_socket_id, msgId);
	}

	_safe_guard_end;
}

void Player::SendToClient(const char * msg, uint32_t msgId)
{
	_safe_guard_begin;

	m_relay_message->Clear();
	m_relay_message->SetMsg(msg);

	if (msgId == 0)
	{
		msgId = m_relay_message->GetProtocolNumber();
	}
	SendToClient(m_relay_message->GetSendString(), msgId);

	_safe_guard_end;
}

void Player::SendToClient(Json::Value& msg, uint32_t msgId)
{
	std::string sendstr = JsonWriter(msg);
	SendToClient(&sendstr, msgId);
}

void Player::SendToDBServer(std::string * str, uint32_t msgId)
{
	_safe_guard_begin;



	_safe_guard_end;
}

//-------------------------------------------------------------------------------
MissionSystem* Player::GetMissionSystem(void)
{
	_safe_guard_begin;

	return &m_missionSys;

	_safe_guard_end;

	return nullptr;
}

//-------------------------------------------------------------------------------
MissionDialogue* Player::GetMissionDialogue(void)
{
	_safe_guard_begin;

	return &m_missionDlg;

	_safe_guard_end;

	return nullptr;
}

//-------------------------------------------------------------------------------
RewardData* Player::GetRewardData(void)
{
	_safe_guard_begin;

	return &m_playerReward;

	_safe_guard_end;

	return nullptr;
}

//-------------------------------------------------------------------------------
NoticeCommon * Player::GetNoticeData(void)
{
	_safe_guard_begin;

	return &m_notice;

	_safe_guard_end;

	return nullptr;
}

//-------------------------------------------------------------------------------
PlayerFixedIntegerArray* Player::GetMissionState(void)
{
	_safe_guard_begin;

	return &m_Buffer;

	_safe_guard_end;

	return nullptr;
}

//-------------------------------------------------------------------------------
NoticeCommonEx * Player::GetNoticeExData(void)
{
	_safe_guard_begin;

	return &m_notice_ex;

	_safe_guard_end;

	return nullptr;
}

//-------------------------------------------------------------------------------
void Player::GetMissionCompleteState()
{
	_safe_guard_begin;

	UIntArray<uint32_t, size_1024>* msState = GetMissionState();
	_safe_check(msState);

	//return message
	_safe_check(m_ask_mission_list_complete);

	//current mission id
	MissionSystem* pMisnSys = GetMissionSystem();
	_safe_check(pMisnSys);
	uint32_t curMisnId = pMisnSys->GetMainMissionId();

	m_ask_mission_list_complete->Clear();
	m_ask_mission_list_complete->SetMissionCompleteState(msState, curMisnId);

	LOG_DEBUG("default","GetMissionCompleteState==>[%s]", m_ask_mission_list_complete->GetSendToServerString()->c_str());

	SendToClient(m_ask_mission_list_complete->GetSendToServerString(),
		m_ask_mission_list_complete->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::GetMissionList()
{
	_safe_guard_begin;

	MissionSystem* missionSys = GetMissionSystem();
	if (nullptr == missionSys)
	{
		return;
	}
	_safe_check(missionSys);

	//return message
	_safe_check(m_ask_mission_list);
	m_ask_mission_list->Clear();
	m_ask_mission_list->SetMissionListData(missionSys);

	LOG_DEBUG("default","GetMissionList==>[%s]", m_ask_mission_list->GetSendToServerString()->c_str());

	SendToClient(m_ask_mission_list->GetSendToServerString(),
		m_ask_mission_list->GetProtocolNumber());

	_safe_guard_end;
}


//-------------------------------------------------------------------------------
void Player::SendMissionDialogueToClient(void)
{
	_safe_guard_begin;

	MissionDialogue* stData = GetMissionDialogue();
	if (nullptr == stData)
	{
		return;
	}
	_safe_check(stData);
	stData->Display();

	_safe_check(m_open_mission_dlg);
	m_open_mission_dlg->SetMissionDialogue(stData);

	SendToClient(m_open_mission_dlg->GetSendToServerString(),
		m_open_mission_dlg->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendRewardDataToClient(void)
{
	_safe_guard_begin;

	RewardData* stData = GetRewardData();
	if (nullptr == stData)
	{
		return;
	}
	_safe_check(stData);

	_safe_check(m_open_reward_dlg);
	m_open_reward_dlg->SetRewardDialogue((*stData));

	SendToClient(m_open_reward_dlg->GetSendToServerString()
		, m_open_reward_dlg->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendNoticeCommonToClient(void)
{
	_safe_guard_begin;

	NoticeCommon* stData = GetNoticeData();
	if (nullptr == stData)
	{
		return;
	}
	_safe_check(stData);
	stData->Display();

	_safe_check(m_notice_common);
	m_notice_common->SetNoticeCommonData((*stData));

	SendToClient(m_notice_common->GetSendToServerString(),
		m_notice_common->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::GetMissionBoxInfoToClient(void)
{
	_safe_guard_begin;

	UIntArray<uint32_t, size_1024>* msState = GetMissionState();
	_safe_check(msState);

	//return message
	_safe_check(m_mission_box_info);

	m_mission_box_info->Clear();
	m_mission_box_info->SetMissionBoxInfo(msState);

	SendToClient(m_mission_box_info->GetSendToServerString(),
		m_mission_box_info->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::GetOfferRewardMissionListToClient(void)
{
	_safe_guard_begin;

	MissionSystem* missionSys = GetMissionSystem();
	if (nullptr == missionSys)
	{
		return;
	}
	_safe_check(missionSys);

	uint32_t rewardTimes = GetFixedValue(Fixed1024::MISSION_OFFER_AWARD_SURPLUS_GET_COUNT);
	uint32_t updateTimes = GetFixedValue(Fixed1024::MISSION_OFFER_AWARD_UPDATE_COUNT);

	_safe_check(m_offer_reward_mission_list);
	m_offer_reward_mission_list->Clear();
	m_offer_reward_mission_list->SetOfferRewardMissionListData(missionSys, rewardTimes, updateTimes);

	std::string* tts = m_offer_reward_mission_list->GetSendToServerString();

	SendToClient(m_offer_reward_mission_list->GetSendToServerString(),
		m_offer_reward_mission_list->GetProtocolNumber());

	LOG_DEBUG("default","common_offer_reward_mission_list_ret to %d|%d -> sendStr: %s",
		m_Account, m_PlayerId, m_offer_reward_mission_list->GetSendToServerString()->c_str());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::UpdateOfferRewardMissionNewList(void)
{
	_safe_guard_begin;

	if (nullptr == m_player_lua_ptr)
	{
		return;
	}
	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardMissionGenerateScript
			, LUA_UpdateOfferMissionList, (int32_t)_usrPosId);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardMissionGenerateScript
			, LUA_UpdateOfferMissionList, (int32_t)_usrPosId);
		LOG_ERROR("default","TryLock FALSE! UpdateOfferRewardMissionNewList");
	}

	uint32_t test = 0;

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::UpdateOfferRewardMissionListByOneItem()
{
	_safe_guard_begin;

	if (nullptr == m_player_lua_ptr)
	{
		return;
	}
	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardMissionGenerateScript
			, LUA_UpdateOfferMissionListByOneItem, (int32_t)_usrPosId);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardMissionGenerateScript
			, LUA_UpdateOfferMissionListByOneItem, (int32_t)_usrPosId);
		LOG_ERROR("default","TryLock FALSE! UpdateOfferRewardMissionListByOneItem");
	}

	_safe_guard_end;
}

void Player::AskOfferRewardMissionList(void)
{
	_safe_guard_begin;

	if (nullptr == m_player_lua_ptr)
	{
		return;
	}
	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();
	uint32_t _account = GetAccount();

	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript
			, LUA_LoadOfferTaskData, _account, _usrPosId);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript
			, LUA_LoadOfferTaskData, _account, _usrPosId);
		LOG_ERROR("default","TryLock FALSE! AskOfferRewardMissionList");
	}

	_safe_guard_end;
}

// 日常任务列表
void Player::AskDailyMissionList(void)
{
	_safe_guard_begin;

	SendDailyMissionList();

	_safe_guard_end;
}

void Player::SendDailyMissionList(void)
{
	_safe_guard_begin;

	MissionSystem* missionSys = GetMissionSystem();
	if (nullptr == missionSys)
	{
		return;
	}
	_safe_check(missionSys);

	//检查更新：有更新先重置内存数据
	std::string  _timeStr = GetDailyTask();

	//获取月卡状态
	uint16_t monthCardState = 0;
	uint32_t mthCardLastTime = GetMonthCard();
	uint32_t _cur_day_time = CUR_DAY;//20161221
	uint32_t _nowTime_day = _cur_day_time % 1000000;//1612212

	// 获取终生卡
	uint32_t frvCard = (GetForeverCard() == 1);

	if (_nowTime_day < mthCardLastTime)
	{
		monthCardState = 1;
	}

	// 是否需要全部更新
	bool _ret = missionSys->CheckResetDailyMissionData(_timeStr);
	if (_ret)
	{
		//重置活跃度与宝箱状态
		SetFixedValue(836, 0);//836:MISSION_DAILY_ACTIVE_BOX_INFO

		uint16_t _fixedPos = GetFixedPosValueByIndex(836);
		SaveSinglePlayerFixedInfo(_fixedPos, true);

		GetMissionBoxInfoToClient();
		LOG_DEBUG("default","GetMissionBoxInfoToClient() CALLED .");

		//重置任务数据
		missionSys->ResetUnlockedDailyMissionData(true, monthCardState, frvCard);
	}
	else
	{
		//检查任务数据
		_ret = missionSys->ResetUnlockedDailyMissionData(false, monthCardState, frvCard);
	}

	//协议返回
	_safe_check(m_ask_daily_mission_list_ret);
	m_ask_daily_mission_list_ret->Clear();
	m_ask_daily_mission_list_ret->SetDailyMissionListData(missionSys);

	LOG_DEBUG("default","SendDailyMissionList==>[%s]", m_ask_daily_mission_list_ret->GetSendToServerString()->c_str());
	SendToClient(m_ask_daily_mission_list_ret->GetSendToServerString(),
		m_ask_daily_mission_list_ret->GetProtocolNumber());

	//更新同步：请求信息后 被定时刷新的可能
	if (_ret)
	{
		std::string _dailyInfo = GetDailyMissionData();
		SetDailyTask(_dailyInfo);
		bool bSave = SetPlayerSomeInfoToRedisDB("dailyTask", _dailyInfo, 1);
		if (!bSave)
		{
			// 保存失败， 随后再次保存
			LOG_ERROR("default","player[%d][%d] save daily task err ", m_Account, m_PlayerId);
		}
	}
	
	_safe_guard_end;
}

uint32_t Player::CheckUnlockedMissionInDailyList(uint32_t missionId)
{
	_safe_guard_begin;

	MissionSystem* _missionSys = GetMissionSystem();
	if (nullptr == _missionSys)
	{
		return 0;
	}
	_safe_check(_missionSys);

	return _missionSys->IsDailyMissionListMember(missionId);

	_safe_guard_end;

	return 0;
}

void Player::SetDailyMissionData(std::string strData)
{
	_safe_guard_begin;

	MissionSystem* _missionSys = GetMissionSystem();
	if (nullptr == _missionSys)
	{
		return;
	}
	_safe_check(_missionSys);

	_missionSys->SetDailyMissionDataByRedisData(strData);

	SetDailyTask(strData);

	_safe_guard_end;
}

std::string Player::GetDailyMissionData(void)
{
	_safe_guard_begin;

	MissionSystem* _missionSys = GetMissionSystem();
	_safe_check(_missionSys);

	return _missionSys->GetDailyMissionDataToRedisData();

	_safe_guard_end;

	return "";
}

std::string Player::GetDailyMissionData( std::string const & strMissionDate )
{
	_safe_guard_begin;

	MissionSystem * ms=GetMissionSystem();
	_safe_check( ms );

	return ms->GetDailyMissionDataToRedisData( strMissionDate );

	_safe_guard_end;

	return std::string().c_str();
}

void Player::KillMonsterMainMission(uint32_t monsterId)
{
	_safe_guard_begin;

	MissionSystem* _pMisnSys =  GetMissionSystem();
	if (nullptr == _pMisnSys)
	{
		return;
	}
	_safe_check(_pMisnSys);

	 uint32_t _misnId = _pMisnSys->GetMainMissionId();
	 
	 if (_misnId <= 0)
		 return;


	 TaskData *_pData = TaskDataTablePtr->GetTaskDataById(_misnId);
	 if (nullptr == _pData)
	 {
		 return;
	 }
	 _safe_check(_pData);

	 uint32_t _misnType = _pData->m_requiretype;
	 if (main_mission_type_6 == _misnType || main_mission_type_7 == _misnType)
	 {

		 _safe_check(m_player_lua_ptr != nullptr);

		 uint32_t _usrPosId = GetSn();
		 int32_t _mission_idx = 0;//主线任务索引
		 if (m_player_lua_ptr->TryLock())
		 {
			 m_player_lua_ptr->RunScriptFunction(LUA_MissionTrunkScript
				 , LUA_KillMonster, (int32_t)_usrPosId, _mission_idx, (int32_t)monsterId);
		 }
		 else
		 {
			 m_player_lua_ptr->RunScriptFunction(LUA_MissionTrunkScript
				 , LUA_KillMonster, (int32_t)_usrPosId, _mission_idx, (int32_t)monsterId);
			 LOG_ERROR("default","TryLock FALSE! KillMonsterMainMission");
		 }
	 }

	_safe_guard_end;

}

// lcl 2017-11-23 时间刷新调用lua
void Player::update_by_time(lua_manager_ptr lua_ptr,unsigned int label_id)
{
	_safe_guard_begin;
	uint32_t _usrPosId = GetSn();
	//_safe_check(m_player_lua_ptr != nullptr);
	if (lua_ptr == nullptr)
	{
		return;
	}
	if (lua_ptr->TryLock())
	{
		lua_ptr->RunScriptFunction(LUA_RedFlagUpdateScript, LUA_UpdateByTime,label_id, m_PlayerId);
	}
	else
	{
		lua_ptr->RunScriptFunction(LUA_RedFlagUpdateScript, LUA_UpdateByTime, label_id, m_PlayerId);
	}
	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::ClickNpc(uint32_t npcId, uint32_t paramFirst, uint32_t paramSecond)
{
	_safe_guard_begin;
	/*临时：屏蔽任务接取*/
	//SendErrMessage();
	//return;

	uint32_t missionId = paramFirst;

	uint32_t _usrPosId = GetSn();

	//int32_t _ret = m_player_lua_ptr->RunScriptFunction(scpriptId, LUA_ClickMissionNPC
	//	, (double)_usrPosId, (double)0, (double)npcId, (double)paramSecond);

	//if (-1 == _ret)
	//{
	//	//可以考虑加一个错误码id
	//	SendErrMessage();
	//}

	if (nullptr == m_player_lua_ptr)
	{
		return;
	}

	_safe_check(m_player_lua_ptr != nullptr);
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction((int32_t)LUA_MissionTrunkScript, LUA_ClickMissionNPC
			, (double)_usrPosId, (double)0.0, (double)npcId, (double)paramSecond);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction((int32_t)LUA_MissionTrunkScript, LUA_ClickMissionNPC
			, (double)_usrPosId, (double)0.0, (double)npcId, (double)paramSecond);
		LOG_ERROR("default","TryLock FALSE! ClickNpc");
	}

	_safe_guard_end;
}

void Player::WildDeliveryDone(void)
{
	_safe_guard_begin;

	//点击送信npc给予信件
	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardDeliveryScript,
			LUA_ClickMissionNPC, (int32_t)_usrPosId);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardDeliveryScript,
			LUA_ClickMissionNPC, (int32_t)_usrPosId);
		LOG_ERROR("default","TryLock FALSE! WildDeliveryDone");
	}

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::CollectMission(uint32_t itemId, uint32_t allCount)
{
	_safe_guard_begin;

	auto *pMissionSys = GetMissionSystem();
	if (nullptr == pMissionSys)
	{
		return;
	}
	_safe_check(pMissionSys);

	uint32_t _missionId = pMissionSys->GetMainMissionId();

	int32_t missionIdx = m_missionSys.GetIndexByMissionID(_missionId);
	if (-1 == missionIdx)
		return;

	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(LUA_MissionTrunkScript, LUA_CollectItem
			, (double)_usrPosId, (double)missionIdx, (double)itemId, (double)allCount);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(LUA_MissionTrunkScript, LUA_CollectItem
			, (double)_usrPosId, (double)missionIdx, (double)itemId, (double)allCount);
		LOG_ERROR("default","TryLock FALSE! CollectMission");
	}

	_safe_guard_end;
}

void Player::CheckMissionByItemChanged(void)
{
	_safe_guard_begin;

	//检查是否满足当前任务类型
	MissionSystem* _pMisnSys = GetMissionSystem();
	if (nullptr == _pMisnSys)
	{
		return;
	}
	_safe_check(_pMisnSys);

	uint32_t _misnId = _pMisnSys->GetMainMissionId();

	if (_misnId <= 0)
		return;

	TaskData *_pData = TaskDataTablePtr->GetTaskDataById(_misnId);
	if (nullptr == _pData)
	{
		return;
	}
	_safe_check(_pData);

	uint32_t _misnType = _pData->m_requiretype;
	if (main_mission_type_8 != _misnType)
		return;

	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();
	int32_t _count = 0;

	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(LUA_MissionTrunkScript,
			LUA_GetItem, _usrPosId, _count);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(LUA_MissionTrunkScript,
			LUA_GetItem, _usrPosId, _count);
		LOG_ERROR("default","TryLock FALSE! CheckMissionByItemChanged");
	}

	_safe_guard_end;
}

void Player::WildCollet(uint32_t itemId)
{
	_safe_guard_begin;

	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();

	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardCollectScript
			, LUA_GetItem, _usrPosId, itemId);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardCollectScript
			, LUA_GetItem, _usrPosId, itemId);
		LOG_ERROR("default","TryLock FALSE! WildCollet");
	}

	_safe_guard_end;
}

void Player::WildDeliveryMoveToNpc(uint32_t npcId, uint32_t npcX, uint32_t npcY)
{
	_safe_guard_begin;

	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardDeliveryScript, 
			LUA_MoveToPosition, (double)_usrPosId, (double)npcId, (double)npcX, (double)npcY);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardDeliveryScript,
			LUA_MoveToPosition, (double)_usrPosId, (double)npcId, (double)npcX, (double)npcY);
		LOG_ERROR("default","TryLock FALSE! WildDeliveryMoveToNpc");
	}

	_safe_guard_end;
}


void Player::KillMonsterWildMission(uint32_t monsterId)
{
	_safe_guard_begin;

	uint32_t _usrPosId = GetSn();
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardKillMonsterScript
			, LUA_KillMonster, _usrPosId, monsterId);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(LUA_OfferRewardKillMonsterScript
			, LUA_KillMonster, _usrPosId, monsterId);
		LOG_ERROR("default","TryLock FALSE! KillMonsterWildMission");
	}

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::MoveToPositionMisson(uint32_t missionId, uint32_t posX, uint32_t posZ)
{
	_safe_guard_begin;

	int32_t missionIdx = m_missionSys.GetIndexByMissionID(missionId);
	if (-1 == missionIdx)
		return;

	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction((int32_t)LUA_MissionTrunkScript, LUA_MoveToPosition,
			(int32_t)_usrPosId, (int32_t)missionIdx, (int32_t)posX, (int32_t)posZ);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction((int32_t)LUA_MissionTrunkScript, LUA_MoveToPosition,
			(int32_t)_usrPosId, (int32_t)missionIdx, (int32_t)posX, (int32_t)posZ);
		LOG_ERROR("default","TryLock FALSE! MoveToPositionMisson");
	}

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::DungeonMission(uint32_t dungeonId)
{
	_safe_guard_begin;

	MissionSystem* _pMisnSys = GetMissionSystem();
	if (nullptr == _pMisnSys)
	{
		return;
	}
	_safe_check(_pMisnSys);

	uint32_t _misnId = _pMisnSys->GetMainMissionId();

	if (_misnId <= 0)
		return;

	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();
	int32_t _idx = 0;
	int32_t _type = 1;

	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction((int32_t)LUA_MissionTrunkScript, LUA_DungeonFinished
			, (int32_t)_usrPosId, _idx, (int32_t)dungeonId, _type);//0:主线任务内存索引,1:通关副本
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction((int32_t)LUA_MissionTrunkScript, LUA_DungeonFinished
			, (int32_t)_usrPosId, _idx, (int32_t)dungeonId, _type);//0:主线任务内存索引,1:通关副本
		LOG_ERROR("default","TryLock FALSE! DungeonMission");
	}

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendNoticeCommonExToClient(void)
{
	_safe_guard_begin;

	NoticeCommonEx* stData = GetNoticeExData();
	if (nullptr == stData)
	{
		return;
	}
	_safe_check(stData);

	m_notice_common_ex->SetNoticeCommonExData((*stData));

	SendToClient(m_notice_common_ex->GetSendToServerString(),
		m_notice_common_ex->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::OperationOfferRewardMission(uint32_t missionPos, uint32_t type)
{
	_safe_guard_begin;

	/*临时：屏蔽任务接取*/
	//SendErrMessage();
	//return;

	uint32_t playerIdx = GetSn();

	MissionSystem* pMission = GetMissionSystem();
	if (nullptr == pMission)
	{
		return;
	}
	_safe_check(pMission);

	//通过前端传入的任务列表索引值，取到当前服务器任务位置
	uint32_t _idx = pMission->GetOfferRewardMissionStartPos();
	missionPos = _idx + missionPos;

	int32_t scriptId = (int32_t)pMission->GetScirptId(missionPos);

	if (nullptr == m_player_lua_ptr)
	{
		return;
	}
	_safe_check(m_player_lua_ptr != nullptr);

	switch (type)
	{
	case 1://接取
	{
		if (m_player_lua_ptr->TryLock())
		{
			m_player_lua_ptr->RunScriptFunction(scriptId
				, LUA_AcceptedOfferRewardMission, playerIdx, missionPos);
		}
		else
		{
			m_player_lua_ptr->RunScriptFunction(scriptId
				, LUA_AcceptedOfferRewardMission, playerIdx, missionPos);
			LOG_ERROR("default","TryLock FALSE! OperationOfferRewardMission 1");
		}
		break;
	}
	case 2://放弃
	{
		if (m_player_lua_ptr->TryLock())
		{
			m_player_lua_ptr->RunScriptFunction(scriptId
				, LUA_GiveUpOfferRewardMission, playerIdx, missionPos);
		}
		else
		{
			m_player_lua_ptr->RunScriptFunction(scriptId
				, LUA_GiveUpOfferRewardMission, playerIdx, missionPos);
			LOG_ERROR("default","TryLock FALSE! OperationOfferRewardMission 2");
		}
		break;
	}
	case 3://立即完成
	{
		if (m_player_lua_ptr->TryLock())
		{
			m_player_lua_ptr->RunScriptFunction(scriptId
				, LUA_CompleteTheMissionImmediately, playerIdx, missionPos);
		}
		else
		{
			m_player_lua_ptr->RunScriptFunction(scriptId
				, LUA_CompleteTheMissionImmediately, playerIdx, missionPos);
			LOG_ERROR("default","TryLock FALSE! OperationOfferRewardMission 3");
		}
		break;
	}
	case 4://领取奖励
	{
		if (m_player_lua_ptr->TryLock())
		{
			m_player_lua_ptr->RunScriptFunction(scriptId
				, LUA_GetRewardProps, playerIdx, missionPos);
		}
		else
		{
			m_player_lua_ptr->RunScriptFunction(scriptId
				, LUA_GetRewardProps, playerIdx, missionPos);
			LOG_ERROR("default","TryLock FALSE! OperationOfferRewardMission X");
		}
		break;
	}
	default:
		break;
	}

	_safe_guard_end;
}

void Player::UpdateMissionItemInfo(uint32_t index)
{
	_safe_guard_begin;

	MissionSystem* pMisn = GetMissionSystem();
	if (nullptr == pMisn)
	{
		return;
	}
	_safe_check(pMisn);

	m_update_mission_item_ret->Clear();
	m_update_mission_item_ret->SetMissionItemInfoData(pMisn, index);

	SendToClient(m_update_mission_item_ret->GetSendToServerString()
		, m_update_mission_item_ret->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendCheckAccountRetToClient(void)
{
	_safe_guard_begin;

	_safe_check(m_GeneralJsonStringRet);

	m_GeneralJsonStringRet->Clear();
	m_GeneralJsonStringRet->ResetProtocolNumber(login_check_account_ret);

	m_GeneralJsonStringRet->SetJsonData("ret", 0);

	m_GeneralJsonStringRet->SetJsonData("account", m_Account);
	m_GeneralJsonStringRet->SetJsonData("playerId", m_PlayerId);
	m_GeneralJsonStringRet->SetJsonData("name", m_Name);

	m_GeneralJsonStringRet->SetJsonData("heroId", m_HeroId);
	m_GeneralJsonStringRet->SetJsonData("areaId", m_Area);

	SendToClient(m_GeneralJsonStringRet->GetSendToServerString(),
		m_GeneralJsonStringRet->GetProtocolNumber());

	LOG_DEBUG("default","%d login_check_account_ret to %d -> sendStr: %s", login_check_account_ret, 
		m_Account, m_GeneralJsonStringRet->GetSendToServerString()->c_str());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendPlayerUpdateItemListRetToClient(std::string & info)
{
	_safe_guard_begin;

	_safe_check(m_GeneralJsonStringRet);

	m_GeneralJsonStringRet->Clear();
	m_GeneralJsonStringRet->ResetProtocolNumber(common_update_item_list_ret);

	m_GeneralJsonStringRet->SetJsonData("ret", 0);

	Json::Value items;
	JsonReader(info, items);

	m_GeneralJsonStringRet->SetJsonData("item", items);

	SendToClient(m_GeneralJsonStringRet->GetSendToServerString(),
		m_GeneralJsonStringRet->GetProtocolNumber());

	_safe_guard_end;
}


//-------------------------------------------------------------------------------

void Player::SendPlayerChatMessageNotifyToClient(uint32_t types, std::string& notify, 
	uint32_t chat_time, uint32_t destAccountId)
{
	_safe_guard_begin;

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendPlayerUnionInfoChangedNotifyToClient(uint32_t types, uint32_t unionId,
	uint32_t unionPosition, std::string& unionName)//, std::string& twGroupId)
{
	_safe_guard_begin;

	_safe_check(m_GeneralJsonStringRet);

	m_GeneralJsonStringRet->Clear();
	m_GeneralJsonStringRet->ResetProtocolNumber(union_information_changed_notify);

	m_GeneralJsonStringRet->SetJsonData("tp", types);
	m_GeneralJsonStringRet->SetJsonData("ui", unionId);
	m_GeneralJsonStringRet->SetJsonData("up", unionPosition);
	m_GeneralJsonStringRet->SetJsonData("un", unionName.c_str());

	//m_GeneralJsonStringRet->SetJsonData("twsoId", twGroupId.c_str());//公会：触宝group_id

	SendToClient(m_GeneralJsonStringRet->GetSendToServerString(),
		m_GeneralJsonStringRet->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::TW_SendGroupIdNotify(uint32_t types, std::string& groupId)
{
	_safe_guard_begin;

	_safe_check(m_tw_group_id_notify);

	m_tw_group_id_notify->Clear();
	m_tw_group_id_notify->ResetProtocolNumber(wt_group_id_changed_push);

	m_tw_group_id_notify->SetJsonData("ret", 0);

	m_tw_group_id_notify->SetJsonData("state", types);
	m_tw_group_id_notify->SetJsonData("group", groupId.c_str());

	LOG_DEBUG("default","===msg===[%d]: %s", wt_group_id_changed_push, m_tw_group_id_notify->GetSendToServerString()->c_str());

	SendToClient(m_tw_group_id_notify->GetSendToServerString(),
		m_tw_group_id_notify->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendPlayerUpdatePetListRetToClient(std::string & info)
{
	_safe_guard_begin;

	_safe_check(m_GeneralJsonStringRet);

	m_GeneralJsonStringRet->Clear();
	m_GeneralJsonStringRet->ResetProtocolNumber(pet_update_pet_list_ret);

	m_GeneralJsonStringRet->SetJsonData("ret", 0);

	Json::Value items;
	JsonReader(info, items);

	m_GeneralJsonStringRet->SetJsonData("item", items);

	SendToClient(m_GeneralJsonStringRet->GetSendToServerString(),
		m_GeneralJsonStringRet->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendPlayerUpdateMountsListRetToClient(std::string & info)
{
	_safe_guard_begin;

	_safe_check(m_GeneralJsonStringRet);

	m_GeneralJsonStringRet->Clear();
	m_GeneralJsonStringRet->ResetProtocolNumber(pet_update_mounts_list_ret);

	m_GeneralJsonStringRet->SetJsonData("ret", 0);

	Json::Value items;
	JsonReader(info, items);

	m_GeneralJsonStringRet->SetJsonData("item", items);

	SendToClient(m_GeneralJsonStringRet->GetSendToServerString(),
		m_GeneralJsonStringRet->GetProtocolNumber());

	_safe_guard_end;
}

void Player::SendPlayerUpdateHeroListRetToClient(std::string & info, int32_t types, int32_t topFc)
{
	_safe_guard_begin;

	_safe_check(m_GeneralJsonStringRet);

	m_GeneralJsonStringRet->Clear();
	m_GeneralJsonStringRet->ResetProtocolNumber(common_update_hero_list_ret);

	m_GeneralJsonStringRet->SetJsonData("ret", 0);

	Json::Value items;
	JsonReader(info, items);

	m_GeneralJsonStringRet->SetJsonData("heros", items);
	m_GeneralJsonStringRet->SetJsonData("types", types);
	m_GeneralJsonStringRet->SetJsonData("topfc", topFc);

	SendToClient(m_GeneralJsonStringRet->GetSendToServerString(),
		m_GeneralJsonStringRet->GetProtocolNumber());

	_safe_guard_end;
}

//void Player::SendPlayerCheckActionToDBServer(uint32_t account, uint32_t _areaId)
//{
//	_safe_guard_begin;
//
//	_safe_check(m_gd_general_message_notify);
//
//	m_gd_general_message_notify->Clear();
//	m_gd_general_message_notify->ResetProtocolNumber(db_check_player_info_to_redis_req);
//
//	m_gd_general_message_notify->SetJsonData("account", account);
//	m_gd_general_message_notify->SetJsonData("areaId", _areaId);
//	m_gd_general_message_notify->SetJsonData("usrSocketId", GetSocketId());
//	m_gd_general_message_notify->SetJsonData("usrPosId", GetSocketId());
//
//	SendToDBServer(m_gd_general_message_notify->GetSendToServerString(),
//		m_gd_general_message_notify->GetProtocolNumber());
//
//	_safe_guard_end;
//}

//-------------------------------------------------------------------------------
void Player::SetName(const char* v)
{
	_safe_guard_begin;

	memset(m_Name, 0, 32);
	memcpy(m_Name, v, strlen(v));

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
char* Player::GetName(void)
{
	_safe_guard_begin;

	return m_Name;

	_safe_guard_end;

	return nullptr;
}

void Player::SetUnionName(const char * v)
{
	_safe_guard_begin;

	memset(m_UnionName, 0, 32);
	memcpy(m_UnionName, v, strlen(v));

	_safe_guard_end;
}

char * Player::GetUnionName(void)
{
	_safe_guard_begin;

	return m_UnionName;

	_safe_guard_end;

	return nullptr;
}

//-------------------------------------------------------------------------------
void Player::SetCurrency(uint16_t idx, uint32_t v)
{
	_safe_guard_begin;

	if (idx < Fixed1024::CURRENCY_GOLD || idx > Fixed1024::CURRENCY_END)
	{
		return;
	}

	SetFixedValue(idx, v);

	LOG_DEBUG("default","Player::SetCurrency idx[%d], v[%d]", idx, v);

	switch (idx)
	{
	case Fixed1024::CURRENCY_GOLD:
		SetUpdateInfoMyFlag(UpdatePlayerInfoType::Gold);
		break;
	case Fixed1024::CURRENCY_DIAMOND:
		SetUpdateInfoMyFlag(UpdatePlayerInfoType::Diamond);
		break;
	case Fixed1024::CURRENCY_PVP_COIN:
		SetUpdateInfoMyFlag(UpdatePlayerInfoType::pvpCoin);
		break;
	case Fixed1024::CURRENCY_ARENA_COIN:
		SetUpdateInfoMyFlag(UpdatePlayerInfoType::arenaCoin);
		break;
	case Fixed1024::CURRENCY_PVE_COIN:
		SetUpdateInfoMyFlag(UpdatePlayerInfoType::pveCoin);
		LOG_DEBUG("default","Player::SetCurrency idx case[%d]", UpdatePlayerInfoType::pveCoin);
		break;
	case Fixed1024::CURRENCY_REWARD_COIN:
		SetUpdateInfoMyFlag(UpdatePlayerInfoType::rewardCoin);
		break;
	case Fixed1024::CURRENCY_UNION_COIN:
		SetUpdateInfoMyFlag(UpdatePlayerInfoType::unionCoin);
		break;
	case Fixed1024::CURRENCY_RUNEMARK:
		SetUpdateInfoMyFlag(UpdatePlayerInfoType::runemark);
		break;
	case Fixed1024::CURRENCY_TICKET:			// 点券
		SetUpdateInfoMyFlag(UpdatePlayerInfoType::ticket);
		break;
	}
	Player::BroadcastSelfPlayer(*this);
	_safe_guard_end;
}

//-------------------------------------------------------------------------------
uint32_t Player::GetCurrency(uint16_t idx)
{
	_safe_guard_begin;

	if (idx < Fixed1024::CURRENCY_GOLD || idx > Fixed1024::CURRENCY_END)
	{
		return -1;
	}

	return GetFixedValue(idx);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SetPingTime(uint32_t ch, uint32_t cl)
{
	_safe_guard_begin;

	m_ping_time = CUR_SEC;

	m_ping->Clear();
	m_ping->SetPingTime(ch, cl, m_ping_time);

	LOG_DEBUG("default","Player::SPing ret[%d]: %s", m_ping->GetProtocolNumber(), m_ping->GetSendToServerString()->c_str());

	SendToClient(m_ping->GetSendToServerString(), m_ping->GetProtocolNumber());

	_safe_guard_end;
}



//-------------------------------------------------------------------------------
bool Player::CheckPingTime(void)
{
	_safe_guard_begin;

	uint64_t _now_time = CUR_MS;

	if (0 == m_ping_time)
	{
		m_ping_time = CUR_SEC;
		return true;
	}

	int32_t nowtime = CUR_SEC;

	if (nowtime - m_ping_time < 60 * 2 )
	{
		return true;
	}
	LOG_INFO("default","player[%d] ping time last[%d] now[%d] time out", m_PlayerId, m_ping_time, nowtime);
	return false;

	_safe_guard_end;

	return false;
}


//-------------------------------------------------------------------------------
void Player::SetDungeonStar(int32_t idx, int32_t v)
{
	_safe_guard_begin;

	int32_t _idx = idx + Fixed1024::DUNGEON_STATE_START;

	if (Fixed1024::DUNGEON_STATE_START > _idx || _idx > Fixed1024::DUNGEON_STATE_END)
	{
		return;
	}

	this->SetFixedValue(_idx, v);

	_safe_guard_end;
}


//-------------------------------------------------------------------------------
int32_t Player::GetLastDungeonId(void)
{
	_safe_guard_begin;

	return -1;

	_safe_guard_end;

	return -1;
}

void Player::SetFuncList(std::string _val)
{
	_safe_guard_begin;

	m_FuncList = _val;

	Json::Value jm;
	JsonReader(m_FuncList, jm);

	for (uint32_t i = 0; i < jm.size(); ++i)
	{
		uint32_t _idx = jm[i].asUInt();
		_idx -= 1; // 以0为基准

		uint32_t _num = Fixed1024::FUNCLIST_841 + _idx / 32;
		
		if (_num <= Fixed1024::FUNCLIST_843)
		{
			this->SetFixedBitValue(_num, _idx % 32, 1, 1);
		}
	}

	_safe_guard_end;
}

std::string Player::GetFuncList(void)
{
	_safe_guard_begin;

	return m_FuncList;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
void Player::SetUpdateInfoFlag(UpdatePlayerInfoType uit)
{
	_safe_guard_begin;

	m_update_info_flag |= uint32_t(uit);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
uint32_t Player::GetUpdateInfoFlag(void)
{
	_safe_guard_begin;

	return m_update_info_flag;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
void Player::ClearUpdateInfoFlag(void)
{
	_safe_guard_begin;

	m_update_info_flag = 0;

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SetUpdateInfoMyFlag(UpdatePlayerInfoType uit)
{
	_safe_guard_begin;

	m_update_info_my_flag |= uint32_t(uit);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
uint32_t Player::GetUpdateInfoMyFlag(void)
{
	_safe_guard_begin;

	return m_update_info_my_flag;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
void Player::ClearUpdateInfoMyFlag(void)
{
	_safe_guard_begin;

	m_update_info_my_flag = 0;

	_safe_guard_end;
}



//-------------------------------------------------------------------------------
PlayerHero * Player::GetAllHeroInfo(uint32_t & size)
{
	_safe_guard_begin;

	size = m_HerosCount;

	return m_playerHero;

	_safe_guard_end;

	return nullptr;
}

//-------------------------------------------------------------------------------
void Player::GetOneHeroInfo(uint32_t heroId, PlayerHero & heroData)
{
	_safe_guard_begin;

	for (uint32_t i = 0; i < max_hero_count; ++i)
	{
		if (m_playerHero[i].mHeroId != heroId)
			continue;

		heroData = m_playerHero[i];
	}

	_safe_guard_end;
}

PlayerHero* Player::GetPlayerHeroInfoByID(uint32_t heroId)
{
	_safe_guard_begin;

	for (uint32_t i = 0; i < max_hero_count; ++i)
	{
		if (m_playerHero[i].mHeroId == heroId)
		{
			return &m_playerHero[i];
		}
	}

	return nullptr;

	_safe_guard_end;

	return nullptr;
}

PlayerHero* Player::GetPlayerHeroEmptyPos()
{
	_safe_guard_begin;

	for (uint32_t i = 0; i < max_hero_count; ++i )
	{
		if (m_playerHero[i].mHeroId == 0)
			return &m_playerHero[i];
	}

	return nullptr;

	_safe_guard_end;

	return nullptr;
}

void Player::SetOneHeroInfo(uint32_t heroId, Json::Value jm)
{
	_safe_guard_begin;

	PlayerHero* hero = GetPlayerHeroInfoByID(heroId);
	if (nullptr == hero)
	{
		hero = GetPlayerHeroEmptyPos();
	}

	if (nullptr != hero)
	{
		//hero->mHeroId = jm["heroId"].asUInt();	
		//hero->mLevel = jm["level"].asUInt();
		//hero->mExps = jm["exps"].asUInt();
		//hero->mStar = jm["star"].asUInt();
		//hero->mGrade = jm["grade"].asUInt();
		//hero->mFightingCapacity = jm["fc"].asUInt();

		//hero->mUUID = jm["uuid"].asString();
		//hero->mName = jm["name"].asString();

		//hero->mEquipment = JsonWriter(jm["equipment"]);
		//hero->mRune = JsonWriter(jm["runes"]);
		//hero->mSkill = JsonWriter(jm["skill"]);

		//(hero->m_property).ResetBasePropertyDataList(jm["baseAttr"]);

		hero->mHeroId = jm["heroId"].asUInt();
		//hero->mHeroId = atoi(jm["heroId"].asCString());
		hero->mLevel = jm["level"].asUInt();
		hero->mExps = jm["exps"].asUInt();
		hero->mStar = jm["star"].asUInt();
		hero->mGrade = jm["grade"].asUInt();
		hero->mFightingCapacity = jm["fc"].asUInt();
		hero->mSkinId = jm["skinId"].asUInt();

		//hero->mUUID = jm["uuid"].asString();//被删减？
		hero->mName = jm["name"].asString();

		hero->mEquipment = JsonWriter(jm["equipment"]);
		hero->mRune = JsonWriter(jm["runes"]);
		hero->mSkill = JsonWriter(jm["skill"]);

		(hero->m_property).ResetBasePropertyDataList(jm["baseAttr"]);

		//hero->m_property->ResetEquipmentPropertyDataList(jm["equipAttr"]);
		//hero->m_property->ResetRunePropertyDataList(jm["runeAttr"]);

		SendToMapUpdateHeroInfo(hero->mHeroId, jm, 1);
	}

	_safe_guard_end;
}

void Player::ResetOneHeroInfo(uint32_t heroId, Json::Value jm)
{
	_safe_guard_begin;

	PlayerHero* hero = GetPlayerHeroInfoByID(heroId);
	if (nullptr != hero)
	{
		hero->mLevel = jm["level"].asUInt();
		hero->mExps = jm["exps"].asUInt();
		hero->mStar = jm["star"].asUInt();
		hero->mGrade = jm["grade"].asUInt();
		hero->mFightingCapacity = jm["fc"].asUInt();

		hero->mEquipment = JsonWriter(jm["equipment"]);
		hero->mRune = JsonWriter(jm["runes"]);
		hero->mSkill = JsonWriter(jm["skill"]);

		(hero->m_property).ResetBasePropertyDataList(jm["baseAttr"]);

		SendToMapUpdateHeroInfo(hero->mHeroId, jm, 2);
	}

	_safe_guard_end;
}

std::string Player::GetDailyTaskDate()
{
	_safe_guard_begin;

	auto ms=GetMissionSystem();
	auto dailyTask= GetDailyTask();

	int iKeyLen=0;
	if ( ms )
	{
		iKeyLen=ms->GetMissionKeyLenth();
	}
	else
	{
		iKeyLen=6;
	}

	if ( iKeyLen!=dailyTask.length() )
	{
		Json::Value _jv;
		_jv.clear();
		JsonReader( dailyTask, _jv );

		Json::Value::Members _jvTemp=_jv.getMemberNames();
		if (_jvTemp.size() <= 0)
		{
			LOG_ERROR("default","daily task is err");
			return "";
		}
		dailyTask=_jvTemp[ 0 ].c_str();
	}

	return dailyTask;

	_safe_guard_end;

	return std::string();
}

void Player::SendToMapUpdateHeroInfo(uint32_t heroid, Json::Value& jm, uint32_t set_type)
{
	if (heroid == 0) {
		heroid = GetHeroId();
	}
	//Json::Value send_to_map;
	PlayerHero* hero = GetPlayerHeroInfoByID(heroid);
	if (!jm.size() && hero != NULL) {
		jm["skinId"] = hero->mSkinId;
		jm["level"] = hero->mLevel;
		
		jm["grade"] = hero->mGrade;
	
		jm["level"] = hero->mLevel;
		jm["exps"] = hero->mExps;
		jm["star"] = hero->mStar;
		jm["grade"] = hero->mGrade;
		jm["fc"] = hero->mFightingCapacity;
		jm["name"] = hero->mName;
		jm["equipment"] = hero->mEquipment;
		jm["runes"] = hero->mRune;
		jm["skill"] = hero->mSkill;

		Json::Value hero_attr;
		for (int32_t i = int32_t(property_type::hp); i < int32_t(property_type::count); ++i)
		{
			hero_attr[i] = (hero->m_property).GetProperty((property_type)i);
		}
		jm["baseAttr"] = hero_attr;
		
	}
	jm["msgid"] = G2M_PLAYER_HERO_INFO_CHANGE_REQUEST;
	jm["set_type"] = set_type;
	jm["heroId"] = heroid;
	jm["HeroId"] = heroid;
	jm["playerId"] = m_PlayerId;
	jm["flag"] = (uint32_t)UpdatePlayerInfoType::heroId;

	if (set_type == 0) {
		return;
	}

	std::string m_send = JsonWriter(jm);

	send_2_map(G2M_PLAYER_HERO_INFO_CHANGE_REQUEST, m_send);
}


//-------------------------------------------------------------------------------
TitleSystem * Player::GetTitleSystem(void)
{
	_safe_guard_begin;

	return &m_titleSys;

	_safe_guard_end;

	return nullptr;
}

uint32_t Player::GetWearingTitleId(void)
{
	_safe_guard_begin;

	TitleSystem* pTitleSys = GetTitleSystem();
	_safe_check(pTitleSys);

	return pTitleSys->GetWaredTitleId();

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
void Player::GetTitleList(void)
{
	_safe_guard_begin;

	TitleSystem* pTitleSys = GetTitleSystem();
	_safe_check(pTitleSys);


	m_title_list->SetTitleListData(pTitleSys);

	SendToClient(m_title_list->GetSendToServerString()
		, m_title_list->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::WearOrTakeOffTitle(uint32_t titleId, uint32_t oprType)
{
	_safe_guard_begin;

	TitleSystem* pTitleSys = GetTitleSystem();
	_safe_check(pTitleSys);

	if (1 == oprType)
	{

		// 如果身上以有穿戴状态称号 更新成当前请求的
		uint16_t idx = pTitleSys->GetIndexByTitleId(titleId);
		pTitleSys->SetTitleState(idx, title_state_type::e_title_wared);

		SendTakeOffOrWearTitleToClient(0, titleId, oprType);

	}
	else if (2 == oprType)
	{

		uint16_t idx = pTitleSys->GetIndexByTitleId(titleId);
		pTitleSys->SetTitleState(idx, title_state_type::e_title_defult);

		SendTakeOffOrWearTitleToClient(0, titleId, oprType);

	}

	//设置他人可见
	SetUpdateInfoFlag(UpdatePlayerInfoType::Title);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendTakeOffOrWearTitleToClient(int32_t ret, uint32_t titleId, uint32_t oprType)
{
	_safe_guard_begin;

	m_title_takeoff_wear->SetTitleTakeOffOrWearData(ret, titleId, oprType);

	SendToClient(m_title_takeoff_wear->GetSendToServerString()
		, m_title_takeoff_wear->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
int16_t Player::GetItemCountByItemId(uint32_t id)
{
	_safe_guard_begin;

	return m_backpack.GetItemCountByItemId(id);

	_safe_guard_end;

	return 0;
}


void Player::OpenWildDig(void)
{
	_safe_guard_begin;


	int32_t _scriptId = 0;// (int32_t)_pMap->GetScriptId();

	int32_t _sceneId = 0;// (int32_t)_pMap->GetSceneId();

	int32_t _x = 0;// (int32_t)GetPosX() * 1000000;

	int32_t _y = 0;// (int32_t)GetPosZ() * 1000000;

	_safe_check(m_player_lua_ptr != nullptr);

	int32_t _usrPosId = (int32_t)GetSn();
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(_scriptId, LUA_GetDigPoints, 
			_usrPosId, _x, _y, _sceneId);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(_scriptId, LUA_GetDigPoints,
			_usrPosId, _x, _y, _sceneId);
		LOG_ERROR("default","TryLock FALSE! OpenWildDig");
	}

	_safe_guard_end;
}

void Player::SendWildDigPoints(const char * idStr, uint32_t sceneId)
{
	_safe_guard_begin;

	m_wild_dig_operation->SetParameter(idStr, sceneId);

	SendToClient(m_wild_dig_operation->GetSendToServerString()
		, m_wild_dig_operation->GetProtocolNumber());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::GetDailyMissionRewardProps(uint32_t missionId, uint32_t firsrPram, uint32_t secondPram)
{
	_safe_guard_begin;

	LOG_DEBUG("default","==================================================================");
	LOG_DEBUG("default","Player::GetDailyMissionRewardProps start.");
	LOG_DEBUG("default","GetDailyMissionRewardProps by mission id [%d]", missionId);

	DailyMissionScriptData* pDaily = DailyMissionScriptManagerPtr->GetDailyMissionScriptDataById(missionId);
	if (nullptr == pDaily)
	{
		return;
	}
	_safe_check(pDaily);

	_safe_check(m_player_lua_ptr != nullptr);

	uint32_t _usrPosId = GetSn();
	int32_t scriptId = (int32_t)pDaily->m_script_id;

	LOG_DEBUG("default","==================================================================");
	LOG_DEBUG("default","GetDailyMissionRewardProps to script id [%d]", scriptId);
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(scriptId, LUA_GiveTheMissionReward
			, _usrPosId, missionId);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(scriptId, LUA_GiveTheMissionReward
			, _usrPosId, missionId);
		LOG_ERROR("default","TryLock FALSE! GetDailyMissionRewardProps");
	}

	LOG_DEBUG("default","==================================================================");
	LOG_DEBUG("default","Player::GetDailyMissionRewardProps end.");
	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::GetActiveRewardBox(uint32_t activeBoxId, uint32_t boxLv, uint32_t param)
{
	_safe_guard_begin;

	_safe_check(m_player_lua_ptr != nullptr);

	int32_t _usrPosId = (int32_t)GetSn();
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(LUA_ActiveBoxScript, LUA_GetActiveBoxReward
			, _usrPosId, (int32_t)activeBoxId, (int32_t)boxLv);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(LUA_ActiveBoxScript, LUA_GetActiveBoxReward
			, _usrPosId, (int32_t)activeBoxId, (int32_t)boxLv);
		LOG_ERROR("default","TryLock FALSE! GetActiveRewardBox");
	}

	_safe_guard_end;
}

void Player::GetWildDiaReward(void)
{
	_safe_guard_begin;


	int32_t _scriptId = GetSceneId();// (int32_t)_pMap->GetScriptId();

	_safe_check(m_player_lua_ptr != nullptr);

	int32_t _usrPosId = (int32_t)GetSn();
	if (m_player_lua_ptr->TryLock())
	{
		m_player_lua_ptr->RunScriptFunction(_scriptId
			, LUA_GetDigExploreReward, _usrPosId);
	}
	else
	{
		m_player_lua_ptr->RunScriptFunction(_scriptId
			, LUA_GetDigExploreReward, _usrPosId);
		LOG_ERROR("default","TryLock FALSE! GetWildDiaReward");
	}

	_safe_guard_end;
}


//-------------------------------------------------------------------------------
void Player::ChangeScene(int32_t flag, uint32_t to, uint32_t from /*= 0*/)
{
	_safe_guard_begin;

	LOG_INFO("default","[cxl]flag:%d, to:%u, from:%u", flag, to, from);
 	uint32_t _current_scene_id = GetSceneId();
	LOG_INFO("default","[cxl]_current_scene_id:%u", _current_scene_id);

	if (_current_scene_id == 0)
	{
		LOG_WARN("default","ChangeScene _current_scene_id=0");
		return;
	}


	if (0 == from)
	{
		from = _current_scene_id;
	}

	SceneConfigureInfo* _scf = SceneConfigureTablePtr->GetScenceConfigureInfoById(to);
	if (nullptr == _scf)
	{
		return;
	}
	_safe_check(_scf != nullptr);

	uint32_t m_script_id = _scf->m_script_id;
	uint32_t _scene_key = _current_scene_id;
	uint32_t playerIdx = GetSn();
	SetSceneClientId(to);
	
	if (m_script_id > 0)
	{

		if (m_player_lua_ptr)
		{
			if (m_player_lua_ptr->TryLock())
			{
				m_player_lua_ptr->RunScriptFunction((int32_t)m_script_id, LUA_PlayerLeaveScene
					, _scene_key, playerIdx, (int32_t)flag, from, to);
			}
			else
			{
				m_player_lua_ptr->RunScriptFunction((int32_t)m_script_id, LUA_PlayerLeaveScene
					, _scene_key, playerIdx, (int32_t)flag, from, to);
				LOG_ERROR("default", "ChangeScene TryLock err");
			}
		}
	}
	else
	{


		if (m_player_lua_ptr)
		{
			if (m_player_lua_ptr->TryLock())
			{
				m_player_lua_ptr->RunScriptFunction(LUA_SecenCommonScript,
					LUA_PlayerLeaveScene, _scene_key, playerIdx, (int32_t)flag, from, to);
			}
			else
			{
				m_player_lua_ptr->RunScriptFunction(LUA_SecenCommonScript,
					LUA_PlayerLeaveScene, _scene_key, playerIdx, (int32_t)flag, from, to);
				LOG_ERROR("default", "ChangeScene TryLock err");
			}
		}
	}
	
	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SetRedPointNotify(std::string _rpp)
{
	_safe_guard_begin;

	_safe_check(m_runtime_info);
	m_runtime_info->m_red_point_string.clear();
	m_runtime_info->m_red_point_string = _rpp;

	SetUpdateInfoMyFlag(UpdatePlayerInfoType::RedPoint);

	_safe_guard_end;
}



//-------------------------------------------------------------------------------
double Player::GetProperty(int32_t heroId, property_type pt)
{
	_safe_guard_begin;

	_safe_check(m_property);

	//	取得player相关属性值
	double _ret =  m_property->GetProperty(pt);

	// 取得具体武将相关属性值
	PlayerHero * hero = GetPlayerHeroInfoByID(heroId);
	if (nullptr != hero)
	{
		_ret += (hero->m_property).GetProperty(pt);
	}

	return _ret;

	_safe_guard_end;

	return 0.0;
}

//-------------------------------------------------------------------------------
void Player::SetTitleProperty(int16_t idx, property_type pt, double val)
{
	_safe_guard_begin;

	if (nullptr == m_property)
	{
		return;
	}
	m_property[idx].SetTitleProperty(pt, val);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendGuideInfo(uint32_t scriptId, int32_t typeId, int32_t stepId, uint32_t widgetId)
{
	_safe_guard_begin;

	m_guide_info->Clear();
	m_guide_info->SetGuideInfo(scriptId, typeId, stepId, widgetId);

	LOG_DEBUG("default","Player::SendGuideInfo : %s", m_guide_info->GetSendToServerString()->c_str());

	SendToClient(m_guide_info->GetSendToServerString(), m_guide_info->GetProtocolNumber());

	_safe_guard_end;
}


//-------------------------------------------------------------------------------
void Player::ManipulateSpecifiedUI(uint32_t UIId, int32_t Action)
{
	_safe_guard_begin;

	m_ui_action->Clear();
	m_ui_action->SetUIInfo(UIId, Action);

	SendToClient(m_ui_action->GetSendString(), m_ui_action->GetProtocolNumber());

	_safe_guard_end;
}



//-------------------------------------------------------------------------------
void Player::SpecifiedBufferPartStart(void)
{
	_safe_guard_begin;

	m_update_specified_buffer_part->Start();

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::AddBufferDate(uint16_t idx)
{
	_safe_guard_begin;
	
	uint32_t _val = m_Buffer.GetValue(idx);

	m_update_specified_buffer_part->AddBufferDate(idx, _val);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SpecifiedBufferPartEnd(void)
{
	_safe_guard_begin;

	m_update_specified_buffer_part->End();

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendSpecifiedBufferPart(void)
{
	_safe_guard_begin;

	SendToClient(m_update_specified_buffer_part->GetSendToServerString(),
		m_update_specified_buffer_part->GetProtocolNumber());
	
	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SavePlayerFixedInfo(void)
{
	_safe_guard_begin;

	SaveAllPlayerFixedInfo(true);

	_safe_guard_end;
}

void Player::SetFixedSdtSaveFlagByPos(uint16_t pos)
{
	_safe_guard_begin;

	uint32_t posV = (uint32_t)pow(2, pos);

	m_update_fixed_flag |= posV;

	_safe_guard_end;
}



//-------------------------------------------------------------------------------
void Player::SaveSinglePlayerFixedInfo(uint32_t pos, bool bSaveToDB)//1~16 part by pos
{
	_safe_guard_begin;

	if (pos < 1 || pos > 16)
	{
		return;
	}

	if (nullptr != m_player_lua_ptr)
	{

		std::string strFiexdInfo = "";

		GetSinglePlayerFixedInfo(pos, strFiexdInfo);

		uint32_t _usrPosId = GetSn();
		if (bSaveToDB)
		{
			bSaveToDB = 1;
		}

		LOG_DEBUG("default","Player Fixed Pos[%d] Info is %s\n", pos, strFiexdInfo.c_str());
		if (strFiexdInfo.empty())
		{
			return;
		}
		//TODO:chenxiaole
		if (m_player_lua_ptr->TryLock())
		{
			m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript, LUA_updatePlayerSingle1024Data, 
				(int32_t)_usrPosId,	(int32_t)m_PlayerId, (int32_t)m_Account, (int32_t)pos, 
				strFiexdInfo.c_str(), (uint16_t)bSaveToDB);
		}
		else
		{
			LOG_ERROR("default","TryLock FALSE! SaveSinglePlayerFixedInfo");
			m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript, LUA_updatePlayerSingle1024Data,
				(int32_t)_usrPosId, (int32_t)m_PlayerId, (int32_t)m_Account, (int32_t)pos,
				strFiexdInfo.c_str(), (uint16_t)bSaveToDB);
		}
	}
	else
	{
		LOG_INFO("default","Daily mission -- SaveSinglePlayerFixedInfo faied by [LuaPtr].");
	}

	_safe_guard_end;
}

void Player::SaveAllPlayerFixedInfo(bool bSaveToDB)
{
	_safe_guard_begin;

	Json::Value jv;

	for (int32_t i = 0; i < 1024; ++i)
	{
		jv.append(m_Buffer.GetValue(i));
	}

	std::string strFiexdInfo = JsonSqlWriter(jv);

	if (nullptr != m_player_lua_ptr)
	{
		uint32_t _usrPosId = GetSn();
		if (m_player_lua_ptr->TryLock())
		{
			m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript, LUA_updatePlayerAll1024Data, (int32_t)_usrPosId,
				(int32_t)m_PlayerId, (int32_t)m_Account, strFiexdInfo.c_str(), (uint16_t)bSaveToDB);
		}
		else
		{
			m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript, LUA_updatePlayerAll1024Data, (int32_t)_usrPosId,
				(int32_t)m_PlayerId, (int32_t)m_Account, strFiexdInfo.c_str(), (uint16_t)bSaveToDB);
			LOG_ERROR("default","TryLock FALSE! SaveAllPlayerFixedInfo");
		}
	}

	_safe_guard_end;
}


void Player::GetSinglePlayerFixedInfo(uint32_t pos, std::string& strInfo)
{
	_safe_guard_begin;

	if (pos < 1 || pos > 16)
	{
		return;
	}

	Json::Value jv;
	int32_t start = (pos - 1) * 64;//以当前pos-1取值，以pos存储
	int32_t end = start + 64;
	for (int32_t i = start; i < end; ++i )
	{
		jv.append(m_Buffer.GetValue(i));
	}

	strInfo = JsonSqlWriter(jv);

	_safe_guard_end;
}



//-------------------------------------------------------------------------------
void Player::SendServerInitFinished(void)
{
	_safe_guard_begin;

	m_server_init_finished->Clear();

	SendToClient(m_server_init_finished->GetSendToServerString(), 
		m_server_init_finished->GetProtocolNumber());

	LOG_DEBUG("default","c_player_data_init_finished to %d|%d -> sendStr: %s", 
		m_Account, m_PlayerId, m_server_init_finished->GetSendToServerString()->c_str());

	_safe_guard_end;
}


//-------------------------------------------------------------------------------
bool Player::SetPlayerSomeInfoToRedisDB(std::string field, std::string value, uint32_t bTable)
{
	_safe_guard_begin;

	if (m_player_lua_ptr != nullptr)
	{
		int32_t _usrPosId = (int32_t)GetSn();
		int32_t _playerId = (int32_t)GetPlayerId();

		bool bLock = m_player_lua_ptr->TryLock();
		//TODO:chenxiaole
		if (bLock)
		{
			m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript, LUA_SetPlayerSomeOneStringInfoToRedisDB
				, _usrPosId, _playerId, field.c_str(), value.c_str(), (int32_t)bTable);
		}
		else
		{
			LOG_ERROR("default","TryLock FALSE! SetPlayerSomeInfoToRedisDB 1");
			m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript, LUA_SetPlayerSomeOneStringInfoToRedisDB
				, _usrPosId, _playerId, field.c_str(), value.c_str(), (int32_t)bTable);
		}

		return bLock;
	}

	_safe_guard_end;
	return false;
}

//-------------------------------------------------------------------------------
void Player::SetPlayerSomeInfoToRedisDB(std::string field, int32_t value)
{
	_safe_guard_begin;

	if (m_player_lua_ptr != nullptr)
	{
		int32_t _usrPosId = (int32_t)GetSn();
		int32_t _playerId = (int32_t)GetPlayerId();
		//TODO:chenxiaole
		if (m_player_lua_ptr->TryLock())
		{
			m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript, LUA_SetPlayerSomeOneNumberInfoToRedisDB
				, _usrPosId, _playerId, value, field.c_str());
		}
		else
		{
			LOG_ERROR("default","TryLock FALSE! SetPlayerSomeInfoToRedisDB 2");
			m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript, LUA_SetPlayerSomeOneNumberInfoToRedisDB
				, _usrPosId, _playerId, value, field.c_str());
		}
	}

	_safe_guard_end;
}


//-------------------------------------------------------------------------------
HeroProperty * Player::GetMainHeroProperty(void)
{
	_safe_guard_begin;

	PlayerHero* _tmp_heroinfo = GetPlayerHeroInfoByID(m_HeroId);
	if (nullptr == _tmp_heroinfo)
	{
		return nullptr;
	}

	return &(_tmp_heroinfo->m_property);

	_safe_guard_end;

	return nullptr;
}


//-------------------------------------------------------------------------------
void Player::CheckSystemMailToSend(void)
{
	_safe_guard_begin;


	_safe_guard_end;
}


//-------------------------------------------------------------------------------
void Player::ClearRockerState(void)
{
	_safe_guard_begin;

	if (nullptr == m_runtime_info)
	{
		return;
	}

	m_runtime_info->m_temp_double_data.SetValue(
		(uint16_t)(player_temp_double::NOW_STATE_DX), 0.0);

	m_runtime_info->m_temp_double_data.SetValue(
		(uint16_t)(player_temp_double::NOW_STATE_DZ), 0.0);

	m_runtime_info->m_temp_double_data.SetValue(
		(uint16_t)(player_temp_double::NOW_STATE_DS), 0.0);

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::GmCurrentMainMission(uint32_t gmVal)
{
	_safe_guard_begin;

	if (m_player_lua_ptr != nullptr)
	{
		uint32_t _playerPos = (int32_t)GetSn();
		if (m_player_lua_ptr->TryLock())
		{
			m_player_lua_ptr->RunScriptFunction(LUA_MissionGmScript, LUA_MissionGm
				, _playerPos, (int32_t)gmVal);
		}
		else
		{
			m_player_lua_ptr->RunScriptFunction(LUA_MissionGmScript, LUA_MissionGm
				, _playerPos, (int32_t)gmVal);
			LOG_ERROR("default","TryLock FALSE! GmCurrentMainMission");
		}
	}

	_safe_guard_end;
}

bool Player::ReadDataFromJson(Json::Value& jsonplayer)
{
	SetNewbieFlag(jsonplayer["newbie"].asInt());
	SetName(jsonplayer["name"].asString().c_str());
	SetArea(jsonplayer["area"].asInt());
	SetPhoto(jsonplayer["photo"].asInt());
	SetPhotoFrame(jsonplayer["photoFrame"].asInt());
	SetLevel(jsonplayer["level"].asInt());
	SetExps(jsonplayer["exps"].asInt());
	SetMaxExps(jsonplayer["maxExps"].asInt());
	SetHeroId(jsonplayer["heroId"].asInt());
	SetHeroSkinId(jsonplayer["heroSkinId"].asInt());
	SetVip(jsonplayer["vip"].asInt());
	SetVipExps(jsonplayer["vExps"].asInt());
	SetAfc(jsonplayer["topFC"].asInt());
	SetUnionId(jsonplayer["unionId"].asInt());
	SetUnionName(jsonplayer["unionName"].asString().c_str());
	SetUnionPosition(jsonplayer["unionPosition"].asInt());
	SetThew(jsonplayer["thew"].asInt());
	//VITALITY = {20, 0, 32}--体力
	SetFixedValue(20, GetThew());
	SetMaxThewTime(jsonplayer["vigour"].asInt());
	SetBuyThew(jsonplayer["buyThew"].asInt());
	SetCurrency(Fixed1024::CURRENCY_GOLD, jsonplayer["gold"].asInt());
	SetCurrency(Fixed1024::CURRENCY_DIAMOND, jsonplayer["diamond"].asInt());
	SetCurrency(Fixed1024::CURRENCY_PVP_COIN, jsonplayer["pvpCoin"].asInt());
	SetCurrency(Fixed1024::CURRENCY_ARENA_COIN, jsonplayer["arenaCoin"].asInt());
	SetCurrency(Fixed1024::CURRENCY_PVE_COIN, jsonplayer["pveCoin"].asInt());
	SetCurrency(Fixed1024::CURRENCY_REWARD_COIN, jsonplayer["rewardCoin"].asInt());
	SetCurrency(Fixed1024::CURRENCY_UNION_COIN, jsonplayer["unionCoin"].asInt());
	SetCurrency(Fixed1024::CURRENCY_RUNEMARK, jsonplayer["runemark"].asInt());
	SetCurrency(Fixed1024::CURRENCY_TICKET, jsonplayer["ticket"].asInt());
	
	SetCurrHeroLevel(jsonplayer["curHerolv"].asInt());

	SetGoldRevive(jsonplayer["goldRevive"].asInt());
	SetDiamondRevive(jsonplayer["diamondRevive"].asInt());

	SetFightHero(jsonplayer["fightHero"].asString());
	SetAdFightHero(jsonplayer["adFightHero"].asString());
	SetEd1FightHero(jsonplayer["ed1FightHero"].asString());
	SetEd2FightHero(jsonplayer["ed2FightHero"].asString());
	SetEd3FightHero(jsonplayer["ed3FightHero"].asString());
	SetEd4FightHero(jsonplayer["ed4FightHero"].asString());
	SetEd5FightHero(jsonplayer["ed5FightHero"].asString());
	SetArenaFightHero(jsonplayer["arenaFightHero"].asString());
	SetThroneFightHero(jsonplayer["throneFightHero"].asString());
	SetExpeditionFightHero(jsonplayer["expeditionFightHero"].asString());
	SetMiniFightHero(jsonplayer["miniFightHero"].asString());

	SetFuncList(jsonplayer["funcList"].asString());
	SetGuide(jsonplayer["guide"].asString());
	SetSceneList(jsonplayer["sceneList"].asString());
	SetDotBuffer(jsonplayer["buffer"].asString());
	SetChangeName(jsonplayer["changeName"].asInt());
	SetExpsPool(jsonplayer["expsPool"].asInt());
	SetPetId(jsonplayer["petId"].asInt());
	SetMountsId(jsonplayer["mountsId"].asInt());
	SetDefPetId(jsonplayer["defPetId"].asInt());
	SetDefMountsId(jsonplayer["defMountsId"].asInt());
	SetDailyMissionData(jsonplayer["dailyTask"].asString());
	SetFirstRechargeState(jsonplayer["FirstRechargeState"].asInt());
	SetRechargeList(jsonplayer["RechargeList"].asString());
	SetMonthCard(jsonplayer["monthCard"].asInt());
	SetForeverCard(jsonplayer["foreverCard"].asInt());
	SetVipGiftBox(jsonplayer["vipGiftBox"].asString());
	SetallServiceAchievementRanking(jsonplayer["AllServiceAchievementRanking"].asInt());
	SetachievementLevel(jsonplayer["AchievementLevel"].asInt());

	SetOnlineTime(jsonplayer["onlineTime"].asInt());
	//PLAYER_ONLINE_REWARD_LAST_TIME = { 1017, 0, 32 }
	SetFixedValue(1017, jsonplayer["online_reward"].asInt());
	//PLAYER_ONCE_ONLINE_TIME 		= {1016, 0, 32}
	SetFixedValue(1016, jsonplayer["once_online"].asInt());

	Json::Value jsTmp;
	jsTmp = jsonplayer[ "continueRecharge" ];
	std::string strjsTmp = JsonWriter( jsTmp );
	if ( jsonplayer.isMember( "continueRecharge" ) )
		m_continueRecharge.ReadFromJson( jsonplayer[ "continueRecharge" ] );


	uint32_t scene_id = jsonplayer["sceneId"].asInt();
	double pos_x = jsonplayer["pos_x"].asDouble();
	double pos_y = jsonplayer["pos_y"].asDouble();
	double pos_z = jsonplayer["pos_z"].asDouble();
	if (scene_id == 0)
	{
		LOG_WARN("default","Player_SetSceneInfoByPlayerIdx error. _scene_id==0");
	}
//	SetSceneId(scene_id);

	SetPlayerState(PlayerState::ps_in_scene);
	PlayerRuntimeInfo* _pri = GetPlayerRuntimeInfo();
	if (_pri != nullptr)
	{
		//	跳转场景后的出生点位置
		_pri->m_temp_double_data.SetValue(
			(uint16_t)(player_temp_double::HOMEPLACE_POS_X), (uint32_t)(pos_x));
		_pri->m_temp_double_data.SetValue(
			(uint16_t)(player_temp_double::HOMEPLACE_POS_Y), (uint32_t)(pos_y));
		_pri->m_temp_double_data.SetValue(
			(uint16_t)(player_temp_double::HOMEPLACE_POS_Z), (uint32_t)(pos_z));
	}
	return true;
}

bool Player::ReadDataFromPtree ( boost::property_tree::ptree && ptree )
{
	SetNewbieFlag ( ptree.get< int > ( "newbie", GetNewbieFlag () ) );
	SetName ( ptree.get< std::string > ( "name", "" ).c_str () );
	SetArea ( ptree.get< int > ( "area", GetArea () ) );
	SetPhoto ( ptree.get< int > ( "photo", GetPhoto () ) );
	SetPhotoFrame ( ptree.get< int > ( "photoFrame", GetPhotoFrame () ) );
	SetLevel ( ptree.get< int > ( "level", GetLevel () ) );
	SetExps ( ptree.get< int > ( "exps", GetExps () ) );
	SetMaxExps ( ptree.get< int > ( "maxExps", GetMaxExps () ) );
	SetHeroId ( ptree.get< int > ( "heroId", GetHeroId () ) );
	SetHeroSkinId ( ptree.get< int > ( "heroSkinId", GetHeroSkinId () ) );
	SetVip ( ptree.get< int > ( "vip", GetVip () ) );
	SetVipExps ( ptree.get< int > ( "vExps", GetVipExps () ) );
	SetAfc ( ptree.get< int > ( "topFC", GetAfc () ) );
	SetUnionId ( ptree.get< int > ( "unionId", GetUnionId () ) );
	SetUnionName ( ptree.get< std::string > ( "unionName", "" ).c_str () );
	SetUnionPosition ( ptree.get< int > ( "unionPosition", GetUnionPosition () ) );
	SetThew ( ptree.get< int > ( "thew", GetThew () ) );
	//VITALITY = {20, 0, 32}--体力
	SetFixedValue ( 20, GetThew () );
	SetMaxThewTime ( ptree.get< int > ( "vigour", GetMaxThewTime () ) );
	SetBuyThew ( ptree.get< int > ( "buyThew", GetBuyThew () ) );
	SetCurrency ( Fixed1024::CURRENCY_GOLD, ptree.get< int > ( "gold", GetCurrency ( Fixed1024::CURRENCY_GOLD ) ) );
	SetCurrency ( Fixed1024::CURRENCY_DIAMOND, ptree.get< int > ( "diamond", GetCurrency ( Fixed1024::CURRENCY_DIAMOND  ) ) );
	SetCurrency ( Fixed1024::CURRENCY_PVP_COIN, ptree.get< int > ( "pvpCoin", GetCurrency ( Fixed1024::CURRENCY_PVP_COIN ) ) );
	SetCurrency ( Fixed1024::CURRENCY_ARENA_COIN, ptree.get< int > ( "arenaCoin", GetCurrency ( Fixed1024::CURRENCY_ARENA_COIN ) ) );
	SetCurrency ( Fixed1024::CURRENCY_PVE_COIN, ptree.get< int > ( "pveCoin", GetCurrency ( Fixed1024::CURRENCY_PVE_COIN ) ) );
	SetCurrency ( Fixed1024::CURRENCY_REWARD_COIN, ptree.get< int > ( "rewardCoin", GetCurrency ( Fixed1024::CURRENCY_REWARD_COIN ) ) );
	SetCurrency ( Fixed1024::CURRENCY_UNION_COIN, ptree.get< int > ( "unionCoin", GetCurrency ( Fixed1024::CURRENCY_UNION_COIN ) ) );
	SetCurrency ( Fixed1024::CURRENCY_RUNEMARK, ptree.get< int > ( "runemark", GetCurrency ( Fixed1024::CURRENCY_RUNEMARK ) ) );
	SetCurrency ( Fixed1024::CURRENCY_TICKET, ptree.get< int > ( "ticket", GetCurrency ( Fixed1024::CURRENCY_TICKET ) ) );

	SetCurrHeroLevel ( ptree.get< int > ( "curHerolv", GetCurrHeroLevel () ) );

	SetGoldRevive ( ptree.get< int > ( "goldRevive", GetGoldRevive () ) );
	SetDiamondRevive ( ptree.get< int > ( "diamondRevive", GetDiamondRevive () ) );

	SetFightHero ( ptree.get< std::string > ( "fightHero", "" ).c_str () );
	SetAdFightHero ( ptree.get< std::string > ( "adFightHero", "" ).c_str () );
	SetEd1FightHero ( ptree.get< std::string > ( "ed1FightHero", "" ).c_str () );
	SetEd2FightHero ( ptree.get< std::string > ( "ed2FightHero", "" ).c_str () );
	SetEd3FightHero ( ptree.get< std::string > ( "ed3FightHero", "" ).c_str () );
	SetEd4FightHero ( ptree.get< std::string > ( "ed4FightHero", "" ).c_str () );
	SetEd5FightHero ( ptree.get< std::string > ( "ed5FightHero", "" ).c_str () );
	SetArenaFightHero ( ptree.get< std::string > ( "arenaFightHero", "" ).c_str () );
	SetThroneFightHero ( ptree.get< std::string > ( "throneFightHero", "" ).c_str () );
	SetExpeditionFightHero ( ptree.get< std::string > ( "expeditionFightHero", "" ).c_str () );
	SetMiniFightHero ( ptree.get< std::string > ( "miniFightHero", "" ).c_str () );

	SetFuncList ( ptree.get< std::string > ( "funcList", "" ).c_str () );
	SetGuide ( ptree.get< std::string > ( "guide", "" ).c_str () );
	SetSceneList ( ptree.get< std::string > ( "sceneList", "" ).c_str () );
	SetDotBuffer ( ptree.get< std::string > ( "buffer", "" ).c_str () );
	SetChangeName ( ptree.get< int > ( "changeName", GetChangeName () ) );
	SetExpsPool ( ptree.get< int > ( "expsPool", GetExpsPool () ) );
	SetPetId ( ptree.get< int > ( "petId", GetPetId () ) );
	SetMountsId ( ptree.get< int > ( "mountsId", GetMountsId () ) );
	SetDefPetId ( ptree.get< int > ( "defPetId", GetDefPetId () ) );
	SetDefMountsId ( ptree.get< int > ( "defMountsId", GetDefMountsId () ) );
	SetDailyMissionData ( ptree.get< std::string > ( "dailyTask", "" ).c_str () );
	SetFirstRechargeState ( ptree.get< int > ( "FirstRechargeState", GetFirstRechargeState () ) );
	SetRechargeList ( ptree.get< std::string > ( "RechargeList", "" ).c_str () );
	SetMonthCard ( ptree.get< int > ( "monthCard", GetMonthCard () ) );
	SetForeverCard ( ptree.get< int > ( "foreverCard", GetForeverCard () ) );
	SetVipGiftBox ( ptree.get< std::string > ( "vipGiftBox", "" ).c_str () );
	SetallServiceAchievementRanking ( ptree.get< int > ( "AllServiceAchievementRanking", m_allServiceAchievementRanking ) );
	SetachievementLevel ( ptree.get< int > ( "AchievementLevel", m_achievementLevel ) );

	SetOnlineTime ( ptree.get< int > ( "onlineTime", GetOnlineTime () ) );
	//PLAYER_ONLINE_REWARD_LAST_TIME = { 1017, 0, 32 }
	SetFixedValue ( 1017, ptree.get< int > ( "online_reward", GetFixedValue ( 1017 ) ) );
	//PLAYER_ONCE_ONLINE_TIME 		= {1016, 0, 32}
	SetFixedValue ( 1016, ptree.get< int > ( "once_online", GetFixedValue ( 1016 ) ) );



	uint32_t scene_id = ptree.get< int > ( "sceneId", GetSceneId () );
	double pos_x = ptree.get< double >( "pos_x", 0 );
	double pos_y = ptree.get< double > ( "pos_y", 0 );
	double pos_z = ptree.get< double > ( "pos_z", 0 );
	m_continueRecharge.ReadFromPtree ( std::move ( ptree ) );

	if( scene_id == 0 )
	{
		LOG_WARN ( "default", "Player_SetSceneInfoByPlayerIdx error. _scene_id==0" );
	}
	//	SetSceneId(scene_id);

	SetPlayerState ( PlayerState::ps_in_scene );
	PlayerRuntimeInfo* _pri = GetPlayerRuntimeInfo ();
	if( _pri != nullptr )
	{
		//	跳转场景后的出生点位置
		_pri->m_temp_double_data.SetValue (
			( uint16_t ) ( player_temp_double::HOMEPLACE_POS_X ), ( uint32_t ) ( pos_x ) );
		_pri->m_temp_double_data.SetValue (
			( uint16_t ) ( player_temp_double::HOMEPLACE_POS_Y ), ( uint32_t ) ( pos_y ) );
		_pri->m_temp_double_data.SetValue (
			( uint16_t ) ( player_temp_double::HOMEPLACE_POS_Z ), ( uint32_t ) ( pos_z ) );
	}

	return true;
}

bool Player::WriteDataToJson(Json::Value& jsonplayer)
{
	jsonplayer["account"] = m_Account;
	jsonplayer["topFC"] = m_Afc;
	jsonplayer["playerId"] = m_PlayerId;
	jsonplayer["name"] = m_Name;
	jsonplayer["level"] = m_Level;
	jsonplayer["exps"] = m_Exps;
	jsonplayer["maxExps"] = m_MaxExps;
	jsonplayer["heroId"] = m_HeroId;
	jsonplayer["heroSkinId"] = m_HeroSkinId;
	jsonplayer["thew"] = m_Thew;
	jsonplayer["maxThewTime"] = m_MaxThewTime;

	jsonplayer["gold"] = GetCurrency(Fixed1024::CURRENCY_GOLD); // 金币
	jsonplayer["diamond"] = GetCurrency(Fixed1024::CURRENCY_DIAMOND); // 钻石
	jsonplayer["pvpCoin"] = GetCurrency(Fixed1024::CURRENCY_PVP_COIN); // 角斗士币
	jsonplayer["arenaCoin"] = GetCurrency(Fixed1024::CURRENCY_ARENA_COIN); // 竞技场币
	jsonplayer["pveCoin"] = GetCurrency(Fixed1024::CURRENCY_PVE_COIN); // 远征币
	jsonplayer["rewardCoin"] = GetCurrency(Fixed1024::CURRENCY_REWARD_COIN); // 悬赏币
	jsonplayer["unionCoin"] = GetCurrency(Fixed1024::CURRENCY_UNION_COIN); // 工会币
	jsonplayer["runemark"] = GetCurrency(Fixed1024::CURRENCY_RUNEMARK); // 战纹碎片

	jsonplayer["photo"] = m_Photo;
	jsonplayer["photoFrame"] = m_PhotoFrame;

	jsonplayer["sysTime"] = (int32_t)CUR_SEC;
	jsonplayer["buyThew"] = m_BuyThew;
	jsonplayer["changeName"] = m_ChangeName;
	jsonplayer["ky"] = GetKey();
	jsonplayer["expsPool"] = m_ExpsPool;

	jsonplayer["unionId"] = m_UnionId;
	jsonplayer["unionName"] = m_UnionName;
	jsonplayer["unionPosition"] = m_UnionPosition;
	jsonplayer["twsoId"] = m_wtUnionGroupId;

	jsonplayer["currHeroLevel"] = m_CurrHeroLevel;

	jsonplayer["petId"] = m_PetId;
	jsonplayer["mountsId"] = m_MountsId;
	jsonplayer["defPetId"] = m_DefPetId;
	jsonplayer["defMountsId"] = m_DefMountsId;

	jsonplayer["vip"] = m_Vip;
	jsonplayer["vExps"] = m_VipExps;

	jsonplayer["monthCard"] = m_MonthCard;
	jsonplayer["foreverCard"] = m_ForeverCard;
	jsonplayer["fRecharge"] = m_FirstRechargeState;
	jsonplayer["ticket"] = GetCurrency(Fixed1024::CURRENCY_TICKET);
	jsonplayer["foreverCardRewardState"] = GetForeverCardRewardState();


	Json::Value rechargeList;
	if (m_RechargeList.length() > 0)
	{
		JsonReader(m_RechargeList, rechargeList);
	}
	jsonplayer["rechargeList"] = rechargeList;

	//
	Json::Value vipGiftBox;
	if (m_VipGiftBox.length() > 0)
	{
		JsonReader(m_VipGiftBox, vipGiftBox);
	}
	jsonplayer["vipGiftBox"] = vipGiftBox;

	Json::Value fightHero;
	if (m_FightHero.length() > 0)
	{
		JsonReader(m_FightHero, fightHero);
	}

	Json::Value adFightHero;
	if (m_AdFightHero.length() > 0)
	{
		JsonReader(m_AdFightHero, adFightHero);
	}

	Json::Value ed1FightHero;
	if (m_Ed1FightHero.length() > 0)
	{
		JsonReader(m_Ed1FightHero, ed1FightHero);
	}

	Json::Value ed2FightHero;
	if (m_Ed2FightHero.length() > 0)
	{
		JsonReader(m_Ed2FightHero, ed2FightHero);
	}

	Json::Value ed3FightHero;
	if (m_Ed3FightHero.length() > 0)
	{
		JsonReader(m_Ed3FightHero, ed3FightHero);
	}

	Json::Value ed4FightHero;
	if (m_Ed4FightHero.length() > 0)
	{
		JsonReader(m_Ed4FightHero, ed4FightHero);
	}

	Json::Value ed5FightHero;
	if (m_Ed5FightHero.length() > 0)
	{
		JsonReader(m_Ed5FightHero, ed5FightHero);
	}

	Json::Value arenaFightHero;
	if (m_ArenaFightHero.length() > 0)
	{
		JsonReader(m_ArenaFightHero, arenaFightHero);
	}

	Json::Value throneFightHero;
	if (m_ThroneFightHero.length() > 0)
	{
		JsonReader(m_ThroneFightHero, throneFightHero);
	}

	Json::Value expeditionFightHero;
	if (m_ExpeditionFightHero.length() > 0)
	{
		JsonReader(m_ExpeditionFightHero, expeditionFightHero);
	}

	Json::Value miniFightHero;
	if (m_MiniFightHero.length() > 0)
	{
		JsonReader(m_MiniFightHero, miniFightHero);
	}

	jsonplayer["fightHero"] = fightHero;
	jsonplayer["adFightHero"] = adFightHero;
	jsonplayer["ed1FightHero"] = ed1FightHero;
	jsonplayer["ed2FightHero"] = ed2FightHero;
	jsonplayer["ed3FightHero"] = ed3FightHero;
	jsonplayer["ed4FightHero"] = ed4FightHero;
	jsonplayer["ed5FightHero"] = ed5FightHero;
	jsonplayer["arenaFightHero"] = arenaFightHero;
	jsonplayer["throneFightHero"] = throneFightHero;
	jsonplayer["expeditionFightHero"] = expeditionFightHero;
	jsonplayer["miniFightHero"] = miniFightHero;
	
	m_continueRecharge.Write2Json( jsonplayer );
	jsonplayer[ "continueRechargeRewardState" ] = m_continueRecharge.GetRewardState().GetState();

	jsonplayer["achievementLevel"] = m_achievementLevel;
	if (m_allServiceAchievementRanking != 0) {
		jsonplayer["allServiceRanking"] = m_allServiceAchievementRanking;
	}

	return true;
}

void Player::PlayerSave()
{
	_safe_guard_begin;

	memset(detail_data, 0, detail_size * sizeof(char));

	m_player_lua_ptr->RunScriptFunctionWithRet(LUA_PlayerManagerScript,
		LUA_DetailSaveToDB, m_PlayerId, detail_data);

	Json::Value m_jv;
	m_jv.clear();

	m_jv["msgid"] = G2D_PLAYER_SAVE_REQ;
	m_jv["account"] = m_Account;
	m_jv["playerId"] = m_PlayerId;
	Json::Value detail_data_json;
	std::string detail_data_str(detail_data);
	JsonReader(detail_data_str, detail_data_json);

	SaveToJson(detail_data_json);
	m_jv["data"] = detail_data_json;

	std::string m_send = JsonWriter(m_jv);

	send_2_db(G2D_PLAYER_SAVE_REQ, m_send, m_PlayerId);

	//交由game sever 发消息, 之后统一给 dbServer处理。
	SyncMyRedisData2Mysql();

	_safe_guard_end;
}

void Player::OnDisconnect()
{
	connected_ = false;
	m_socket_id = -1;
	disconnect_time_ = CUR_SEC;
}

int32_t Player::ChangeNumber(int32_t type, int32_t value)
{
	int32_t ret = -1;
	int32_t lua_ret = m_player_lua_ptr->RunScriptFunctionWithRet(LUA_PlayerManagerScript,
		LUA_ChangePlayerNumber, (int32_t)m_PlayerId, type, value, &ret);

	LOG_ERROR("default","ret:%d lua_ret:%d", ret, lua_ret);
	return ret;
}

void Player::OnNewDay()
{
	m_RecoverThewCount = CUR_SEC;
	LOG_DEBUG("default","player[%d] on new day", m_PlayerId);
}

void Player::OnNewZeroDay()
{
	LOG_DEBUG("default","player[%d] on new zero day", m_PlayerId);

	SetOnlineTime(0);

	int32_t lua_ret = m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript,
		LUA_OnNewZeroDay, (int32_t)m_PlayerId);

	//  新的一天刷新活动次数
	role_activity_.onNewDay(*this);
}

void Player::OnNewWeek()
{
	LOG_DEBUG("default","player[%d] on new week", m_PlayerId);
}

void Player::OnNewMonth()
{
	LOG_DEBUG("default","player[%d] on new month", m_PlayerId);

	int32_t lua_ret = m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript,
		LUA_OnNewMonth, (int32_t)m_PlayerId);
}

bool Player::PlayerInGame()
{
	return PlayerState::ps_pre_enter_scene == m_player_state ? false: true;
}

int32_t Player::RefreshLastSaveTime()
{
	last_save_time_ = CUR_SEC;
	return last_save_time_;
}

void Player::UpdatePlayerInfoPing()
{
	// 定时更新 被动技能 发送给客户端
	if (passivity_skill().Size() > 0) {
		SetFixedValue((int16_t)UpdatePlayerInfoType::passivity_skill, 1);
		SetUpdateInfoMyFlag(UpdatePlayerInfoType::passivity_skill);
	}

	m_player_lua_ptr->RunScriptFunction(LUA_PlayerManagerScript,
		LUA_UpdatePlayerInfoPing, m_PlayerId, m_ping_time);
}

void Player::SetLevel(int32_t level)
{
	m_Level = level;
	CPlayerInfo* playerinfo = CPlayerInfoMgr::GetInstance().GetPlayerInfoByPlayerID(m_PlayerId);
	if (playerinfo != NULL)
	{
		playerinfo->set_level(m_Level);
	}
}

void Player::SetAfc(int32_t afc)
{
	m_Afc = afc;
	CPlayerInfo* playerinfo = CPlayerInfoMgr::GetInstance().GetPlayerInfoByPlayerID(m_PlayerId);
	if (playerinfo != NULL)
	{
		playerinfo->set_afc(m_Afc);
	}
}

void Player::SetHeroId(uint32_t heroid)
{
	m_HeroId = heroid;
	CPlayerInfo* playerinfo = CPlayerInfoMgr::GetInstance().GetPlayerInfoByPlayerID(m_PlayerId);
	if (playerinfo != NULL)
	{
		playerinfo->set_heroid(m_HeroId);
	}

	// sync to map
	uint32_t flag = 0;
	flag |= (uint32_t)UpdatePlayerInfoType::heroId;
	flag |= (uint32_t)UpdatePlayerInfoType::heroSkinId;
	SyncPlayer2MapByFlag(flag);
}

void Player::SetHeroSkinId(uint32_t heroskinid)
{
	m_HeroSkinId = heroskinid;
	CPlayerInfo* playerinfo = CPlayerInfoMgr::GetInstance().GetPlayerInfoByPlayerID(m_PlayerId);
	if (playerinfo != NULL)
	{
		playerinfo->set_heroSkinId(m_HeroSkinId);
	}
	uint32_t flag = 0;
	flag |= (uint32_t)UpdatePlayerInfoType::heroSkinId;
	SyncPlayer2MapByFlag(flag);
}

void Player::SetVip(int32_t vip)
{
	m_Vip = vip;
	CPlayerInfo* playerinfo = CPlayerInfoMgr::GetInstance().GetPlayerInfoByPlayerID(m_PlayerId);
	if (playerinfo != NULL)
	{
		playerinfo->set_vip(m_Vip);
	}
}


void Player::SetPhotoFrame(uint32_t photoframe)
{
	m_PhotoFrame = photoframe;
	CPlayerInfo* playerinfo = CPlayerInfoMgr::GetInstance().GetPlayerInfoByPlayerID(m_PlayerId);
	if (playerinfo != NULL)
	{
		playerinfo->set_photoframe(m_PhotoFrame);
	}
	//uint32_t flag = 0;
	//flag |= (uint32_t)UpdatePlayerInfoType::;
	//SyncPlayer2MapByFlag(flag);
}

void Player::SaveToJson(Json::Value& detail_data)
{
	Json::Value role_activity_json;
	role_activity_.WriteToJson(role_activity_json);
	detail_data["role_activity"] = role_activity_json;
	detail_data["update_time"] = update_time_;

	// 阵型存储
	Json::Value role_square_json;
	role_fight_square_.WriteToJson(role_square_json);
	detail_data["role_square"] = role_square_json;

	// 被动技能存储
	Json::Value passivity_skill_json;
	passivity_skill_.WriteToJson(passivity_skill_json);
	detail_data["passivity_skill"] = passivity_skill_json;
}

void Player::LoadFromJson(Json::Value& detail_data)
{
	Json::Value role_activity_json = detail_data["role_activity"];
	role_activity_.ReadFromJson(role_activity_json);
	update_time_ = detail_data["update_time"].asInt();

	Json::Value role_square_json = detail_data["role_square"];
	role_fight_square_.ReadFromJson(role_square_json);

	// 加载被动技能
	Json::Value passivity_skill_json = detail_data["passivity_skill"];
	passivity_skill_.ReadFromJson(passivity_skill_json, m_PlayerId);
}

void Player::FillBaseInfoToJson(Json::Value& player_json)
{
	player_json.clear();
	player_json["playerid"] = m_PlayerId;
	player_json["account"] = m_Account;
	player_json["name"] = m_Name;
	player_json["level"] = m_Level;
	player_json["heroid"] = m_HeroId;
	player_json["photo"] = m_PhotoFrame;
	player_json["afc"] = m_Afc;
	player_json["unionid"] = m_UnionId;
	player_json["unionname"] = m_UnionName;
	player_json["heroskin"] = m_HeroSkinId;
	player_json["vip"] = m_Vip;
}


void Player::SerialToJson(Json::Value& baseinfo)
{
	baseinfo.clear();
	baseinfo["si"] = GetSceneId();
	baseinfo["px"] = position().x();
	baseinfo["pz"] = position().z();
	baseinfo["py"] = position().y();
	baseinfo["td"] = 0;
	baseinfo["tp"] = 0;
	baseinfo["ky"] = GetKey();
	baseinfo["ai"] = GetAccount();
	baseinfo["pi"] = GetPlayerId();
	baseinfo["ri"] = GetHeroId();
	baseinfo["tl"] = 0;
	baseinfo["nm"] = std::string(GetName());
	baseinfo["mountsState"] = std::to_string(GetMountsState());
	baseinfo["unId"] = GetUnionId();
	baseinfo["unNm"] = GetUnionName();
	baseinfo["pt"] = GetPetId();
	baseinfo["mt"] = GetMountsId();
	baseinfo["skinid"] = GetHeroSkinId();
	baseinfo["areaId"] = GetArea();
	baseinfo["rc"] = 0;
}


//-------------------------------------------------------------------------------
void Player::PushChatMessageToClient(uint32_t type, const char* pContant
	, uint32_t srcPid, uint32_t srcAid, uint32_t Hid, uint32_t Vid, const char* name
	, uint32_t horn /*= 0*/, uint32_t shareType/* = 0*/)
{
	_safe_guard_begin;

	_safe_check(m_chat_message_general_push);

	m_chat_message_general_push->Clear();
	m_chat_message_general_push->ResetProtocolNumber(common_server_chat_msg_notify_push);

	uint32_t _chat_time = CUR_SEC;

	m_chat_message_general_push->SetJsonData("pid", srcPid);
	m_chat_message_general_push->SetJsonData("aid", srcAid);
	m_chat_message_general_push->SetJsonData("pp", Hid);
	m_chat_message_general_push->SetJsonData("pv", Vid);
	m_chat_message_general_push->SetJsonData("tp", type);
	m_chat_message_general_push->SetJsonData("c", pContant);
	m_chat_message_general_push->SetJsonData("ct", _chat_time);
	m_chat_message_general_push->SetJsonData("pn", name);
	m_chat_message_general_push->SetJsonData("hn", horn);
	m_chat_message_general_push->SetJsonData("sr", shareType);//分享类型字段

	SendToClient(m_chat_message_general_push->GetSendToServerString()
		, m_chat_message_general_push->GetProtocolNumber());

	_safe_guard_end;
}

void Player::PushChatMessageToClient(uint32_t type, const char* pContant,
	uint32_t srcPid, uint32_t srcAid, uint32_t Hid, uint32_t Vid, const char* name
	, const char* pGvcId, double dGvcTime, const char* pGvcPart)
{
	_safe_guard_begin;

	_safe_check(m_chat_message_general_push);

	m_chat_message_general_push->Clear();
	m_chat_message_general_push->ResetProtocolNumber(common_server_chat_msg_notify_push);

	uint32_t _chat_time = CUR_SEC;

	m_chat_message_general_push->SetJsonData("pid", srcPid);
	m_chat_message_general_push->SetJsonData("aid", srcAid);
	m_chat_message_general_push->SetJsonData("pp", Hid);
	m_chat_message_general_push->SetJsonData("pv", Vid);
	m_chat_message_general_push->SetJsonData("tp", type);
	m_chat_message_general_push->SetJsonData("c", pContant);
	m_chat_message_general_push->SetJsonData("ct", _chat_time);
	m_chat_message_general_push->SetJsonData("pn", name);

	m_chat_message_general_push->SetJsonData("gvid", pGvcId);
	m_chat_message_general_push->SetJsonData("gvti", dGvcTime);
	m_chat_message_general_push->SetJsonData("gvte", pGvcPart);

	SendToClient(m_chat_message_general_push->GetSendToServerString()
		, m_chat_message_general_push->GetProtocolNumber());

	_safe_guard_end;
}

void Player::SaveChatRecord(uint32_t cType, uint32_t destId, const char* content
	, Player& pPlayer, uint16_t	hornType/* = 0*/, uint16_t shareType/* = 0*/)
{
	_safe_guard_begin;

	_safe_check(m_player_lua_ptr);

	//聊天记录
	uint32_t _chat_time = CUR_SEC;

	Json::Value _record;
	_record.clear();

	_record["aid"] = GetAccount();
	_record["c"] = content;
	_record["ct"] = _chat_time;
	_record["pid"] = GetPlayerId();
	_record["pn"] = GetName();
	_record["pp"] = GetHeroId();
	_record["pv"] = GetVip();
	_record["tp"] = cType;

	_record["hn"] = hornType;
	_record["sr"] = shareType;

	uint32_t _player_id = GetPlayerId();

	m_player_lua_ptr->RunScriptFunction(LUA_ChatFunctionScript
		, LUA_SavePlayerChatMessage, _player_id, cType, destId, JsonWriter(_record).c_str());

	_safe_guard_end;
}

void Player::SaveChatRecord(uint32_t cType, uint32_t destId, const char* content
	, Player& pPlayer, const char* pGvcId, double dGvcTime, const char* pGvcPart)
{
	_safe_guard_begin;

	_safe_check(m_player_lua_ptr);

	//聊天记录
	uint32_t _chat_time = CUR_SEC;

	Json::Value _record;
	_record.clear();

	_record["aid"] = GetAccount();
	_record["c"] = content;
	_record["ct"] = _chat_time;
	_record["pid"] = GetPlayerId();
	_record["pn"] = GetName();
	_record["pp"] = GetHeroId();
	_record["pv"] = GetVip();
	_record["tp"] = cType;

	_record["gvid"] = pGvcId;
	_record["gvti"] = dGvcTime;
	_record["gvte"] = pGvcPart;

	uint32_t _player_id = GetPlayerId();

	m_player_lua_ptr->RunScriptFunction(LUA_ChatFunctionScript
		, LUA_SavePlayerChatMessage, _player_id, cType, destId, JsonWriter(_record).c_str());

	_safe_guard_end;
}

void Player::SendChatRetMessageToClient(uint16_t retVal/* = 0*/)
{
	_safe_guard_begin;

	_safe_check(m_chat_message_general_ret);

	m_chat_message_general_ret->Clear();
	m_chat_message_general_ret->ResetProtocolNumber(player_chat_message_ret);

	m_chat_message_general_ret->SetJsonData("pid", GetPlayerId());
	m_chat_message_general_ret->SetJsonData("ret", retVal);

	SendToClient(m_chat_message_general_ret->GetSendToServerString()
		, m_chat_message_general_ret->GetProtocolNumber());

	_safe_guard_end;
}

void Player::SendGmMarqueeToClient(uint32_t spn, uint32_t tp, std::string msg
	, std::string playerName, uint32_t priority/* = 1*/)
{
	_safe_guard_begin;

	_safe_check(m_notice_common);

	m_notice_common->Clear();
	m_notice_common->ResetProtocolNumber(common_notice_common_ret);

	NoticeCommon stData;

	stData.SetUserVal1(spn);
	stData.SetUserVal2(tp);
	stData.SetUserVal3(priority);
	stData.SetOption1(msg.c_str());
	stData.SetOption2(playerName.c_str());
	std::string s3 = "";
	stData.SetOption3(s3.c_str());

	/*
	//
	"msgid":295,//协议ID
	"opt1":1,//子协议号:暂无具体意义
	"opt2" : 5, //1跑马灯 2任务 3特效 4奖励面板 5蓝喇叭
	"opt3" : 1,//优先级 1～7 从高到低
	"ret" : 0,
	"uid" : 0,
	"user1" : "12344321", //消息内容
	"user2" : "不败的王子",//玩家名字
	"user3" : ""//空的
	*/

	m_notice_common->SetNoticeCommonData(stData);

	SendToClient(m_notice_common->GetSendToServerString(), m_notice_common->GetProtocolNumber());

	LOG_DEBUG("default", "SendGmMarqueeToClient msgid:[%d], msg[%s].", m_notice_common->GetProtocolNumber()
		, m_notice_common->GetSendToServerString());

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::SendFriendChatRetMessageToClient(uint32_t tarId, uint32_t cType, uint16_t retVal/* = 0*/)
{
	_safe_guard_begin;

	LOG_DEBUG("default", "SendFriendChatRetMessageToClient start.");

	LOG_DEBUG("default", "SendFriendChatRetMessageToClient param: tarId[%d], cType[%d], retVal[%d].", tarId, cType, retVal);

	_safe_check(m_chat_firend_message_ret);

	m_chat_firend_message_ret->Clear();
	m_chat_firend_message_ret->ResetProtocolNumber(player_friend_chat_message_ret);

	m_chat_firend_message_ret->SetJsonData("pid", GetPlayerId());
	m_chat_firend_message_ret->SetJsonData("tid", tarId);
	m_chat_firend_message_ret->SetJsonData("ret", retVal);
	m_chat_firend_message_ret->SetJsonData("ctp", cType);

	SendToClient(m_chat_firend_message_ret->GetSendToServerString()
		, m_chat_firend_message_ret->GetProtocolNumber());

	LOG_DEBUG("default", "SendFriendChatRetMessageToClient end.");

	_safe_guard_end;
}

//-------------------------------------------------------------------------------
void Player::PushChatMessageToFriendClient(uint32_t type, const char* pContant,
	uint32_t srcPid, uint32_t srcAid, uint32_t Hid, uint32_t Vid, const char* name
	, uint32_t tarId, uint32_t cType)
{
	_safe_guard_begin;

	_safe_check(m_chat_friend_message_push);

	m_chat_friend_message_push->Clear();
	m_chat_friend_message_push->ResetProtocolNumber(common_server_chat_friend_msg_notify_push);

	uint32_t _chat_time = CUR_SEC;

	m_chat_friend_message_push->SetJsonData("pid", srcPid);
	m_chat_friend_message_push->SetJsonData("aid", srcAid);
	m_chat_friend_message_push->SetJsonData("pp", Hid);
	m_chat_friend_message_push->SetJsonData("pv", Vid);
	m_chat_friend_message_push->SetJsonData("tp", type);
	m_chat_friend_message_push->SetJsonData("c", pContant);
	m_chat_friend_message_push->SetJsonData("ct", _chat_time);
	m_chat_friend_message_push->SetJsonData("pn", name);
	m_chat_friend_message_push->SetJsonData("tid", tarId);
	m_chat_friend_message_push->SetJsonData("ctp", cType);

	SendToClient(m_chat_friend_message_push->GetSendToServerString()
		, m_chat_friend_message_push->GetProtocolNumber());

	_safe_guard_end;
}

void Player::PushChatMessageToFriendClient(uint32_t type, const char* pContant,
	uint32_t srcPid, uint32_t srcAid, uint32_t Hid, uint32_t Vid, const char* name
	, uint32_t tarId, uint32_t cType, const char* pGvcId, double dGvcTime, const char* pGvcPart)
{
	_safe_guard_begin;

	_safe_check(m_chat_friend_message_push);

	m_chat_friend_message_push->Clear();
	m_chat_friend_message_push->ResetProtocolNumber(common_server_chat_friend_msg_notify_push);

	uint32_t _chat_time = CUR_SEC;

	m_chat_friend_message_push->SetJsonData("pid", srcPid);
	m_chat_friend_message_push->SetJsonData("aid", srcAid);
	m_chat_friend_message_push->SetJsonData("pp", Hid);
	m_chat_friend_message_push->SetJsonData("pv", Vid);
	m_chat_friend_message_push->SetJsonData("tp", type);
	m_chat_friend_message_push->SetJsonData("c", pContant);
	m_chat_friend_message_push->SetJsonData("ct", _chat_time);
	m_chat_friend_message_push->SetJsonData("pn", name);
	m_chat_friend_message_push->SetJsonData("tid", tarId);
	m_chat_friend_message_push->SetJsonData("ctp", cType);

	m_chat_friend_message_push->SetJsonData("gvid", pGvcId);
	m_chat_friend_message_push->SetJsonData("gvti", dGvcTime);
	m_chat_friend_message_push->SetJsonData("gvte", pGvcPart);

	SendToClient(m_chat_friend_message_push->GetSendToServerString()
		, m_chat_friend_message_push->GetProtocolNumber());

	_safe_guard_end;
}

void Player::getChatMessageJson(std::string& chatstr, uint32_t type, const char* pContant,
	uint32_t srcPid, uint32_t srcAid, uint32_t Hid, uint32_t Vid, const char* name
	, uint32_t tarId, uint32_t cType, const char* pGvcId, double dGvcTime, const char* pGvcPart)
{
	_safe_guard_begin;

	uint32_t _chat_time = CUR_SEC;
	Json::Value mjson;
	mjson["pid"] = srcPid;
	mjson["aid"] = srcAid;
	mjson["pp"] = Hid;
	mjson["pv"] = Vid;
	mjson["tp"] = type;
	mjson["c"] = pContant;
	mjson["ct"] = _chat_time;
	mjson["pn"] = name;
	mjson["tid"] = tarId;
	mjson["ctp"] = cType;
	mjson["gvid"] = pGvcId;
	mjson["gvti"] = dGvcTime;
	mjson["gvte"] = pGvcPart;
	mjson["msgid"] = C2G_SAVE_PLAYER_OFFLINE_CHAT;

	chatstr = JsonWriter(mjson);

	_safe_guard_end;
}
//-------------------------------------------------------------------------------
void Player::SyncPlayer2MapByFlag(int32_t flag)
{
	if (flag <= 0) {
		LOG_DEBUG("default", "");
		return;
	}
	Json::Value m_jv;
	m_jv["msgid"] = map_player_change_something_notify;
	m_jv["ret"] = 0;
	m_jv["flag"] = flag;
	m_jv["_gate_fd"] = m_socket_id;
	m_jv["playerId"] = m_PlayerId;

	if (flag & uint32_t(UpdatePlayerInfoType::heroId)) {
		m_jv["HeroId"] = GetHeroId();
	}

	/*
	if (flag & uint32_t(UpdatePlayerInfoType::name)) {
		m_jv["arg2"] = m_Name;
	}
	*/

	if (flag &uint32_t(UpdatePlayerInfoType::unionId)) {
		m_jv["UnionId"] = GetUnionId();
	}

	if (flag & uint32_t(UpdatePlayerInfoType::unionName)) {
		m_jv["UnionName"] = GetUnionName();
	}

	if (flag & uint32_t(UpdatePlayerInfoType::pet)) {
		m_jv["PetId"] = GetPetId();
	}

	if (flag & uint32_t(UpdatePlayerInfoType::mount)) {
		m_jv["MountsId"] = GetMountsId();
		m_jv["MountsState"] = GetMountsState();
	}

	if (flag & uint32_t(UpdatePlayerInfoType::heroSkinId)) {
		m_jv["HeroSkinId"] = GetHeroSkinId();
	}

	if (flag & uint32_t(UpdatePlayerInfoType::Exp)) {
		m_jv["Level"] = GetLevel();
	}


	std::string send_str = JsonWriter(m_jv);
	send_2_map(map_player_change_something_notify, send_str);
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------

void Player::BroadcastSelfPlayer(Player & player, uint32_t flag)
{
	flag = flag > 0 ? flag : player.GetUpdateInfoMyFlag();


	Json::Value m_msg_json;
	Json::Value msg_json_broad;
	uint32_t flag_broadcast = 0;

	flag &= ~(uint32_t)UpdatePlayerInfoType::Hp;

	Json::Value msg_json;

	if ((flag & uint32_t(UpdatePlayerInfoType::Gold)) > 0)
	{
		msg_json["gd"] = player.GetCurrency(Fixed1024::CURRENCY_GOLD);
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::Diamond)) > 0)
	{
		msg_json["dd"] = player.GetCurrency(Fixed1024::CURRENCY_DIAMOND);
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::Exp)) > 0)
	{
		msg_json["ep"] = player.GetExps();
		msg_json["plv"] = player.GetLevel();
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::RedPoint)) > 0)
	{
		PlayerRuntimeInfo* _tpri = player.GetPlayerRuntimeInfo();

		if (NULL != _tpri && _tpri->m_red_point_string.length() > 0)
		{
			Json::Value jm;
			JsonReader(_tpri->m_red_point_string, jm);

			msg_json["rd"] = jm;

			_tpri->m_red_point_string.clear();
		}
	}


	if ((flag & uint32_t(UpdatePlayerInfoType::pvpCoin)) > 0)
	{
		msg_json["ppc"] = player.GetCurrency(Fixed1024::CURRENCY_PVP_COIN);
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::arenaCoin)) > 0)
	{
		msg_json["ac"] = player.GetCurrency(Fixed1024::CURRENCY_ARENA_COIN);
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::pveCoin)) > 0)
	{
		msg_json["pec"] = player.GetCurrency(Fixed1024::CURRENCY_PVE_COIN);
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::rewardCoin)) > 0)
	{
		msg_json["rc"] = player.GetCurrency(Fixed1024::CURRENCY_REWARD_COIN);
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::unionCoin)) > 0)
	{
		msg_json["ucn"] = player.GetCurrency(Fixed1024::CURRENCY_UNION_COIN);
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::Title)) > 0)
	{
		msg_json["tl"] = player.GetWearingTitleId();
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::Vitality)) > 0)
	{
		msg_json["vt"] = player.GetThew();
		msg_json["mtwt"] = player.GetMaxThewTime();
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::unionId)) > 0)
	{
		msg_json["unId"] = player.GetUnionId();
	}
	if ((flag & uint32_t(UpdatePlayerInfoType::unionName)) > 0)
	{
		msg_json["unNm"] = player.GetUnionName();
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::pet)) > 0)
	{
		msg_json["pt"] = player.GetPetId();
	}
	if ((flag & uint32_t(UpdatePlayerInfoType::mount)) > 0)
	{
		msg_json["mt"] = player.GetMountsId();
		msg_json["mountsState"] = player.GetMountsState();
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::heroId)) > 0)
	{
		msg_json["ri"] = player.GetHeroId();
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::heroSkinId)) > 0)
	{
		msg_json["rsi"] = player.GetHeroSkinId();
	}

	//if ((flag & uint32_t(UpdatePlayerInfoType::expeditionRetimes)) > 0)
	//{
	//	msg_json["rtm"] = player.GetFixedValue(Fixed1024::EXPEDITION_RESET_COUNT_MAX);
	//}
	// 点券 
	if ((flag & uint32_t(UpdatePlayerInfoType::ticket)) > 0)
	{
		msg_json["tk"] = player.GetFixedValue(Fixed1024::CURRENCY_TICKET);
	}

	if ((flag & uint32_t(UpdatePlayerInfoType::passivity_skill)) > 0 || player.passivity_skill().FlushToClient())
	{
		Json::Value target;
		player.passivity_skill().WriteToJson(target);
		msg_json["passivity_skill"] = target;
	}

	// 战纹碎片
	if ((flag & uint32_t(UpdatePlayerInfoType::runemark)) > 0)
	{
		msg_json["rnmk"] = player.GetCurrency(Fixed1024::CURRENCY_RUNEMARK);
	}

	// 需要广播的消息
	Json::Value m_msg_json_self;
	// 通知到自己即可

	msg_json["si"] = player.GetSceneId();
	msg_json["ky"] = player.GetKey();
	msg_json["fg"] = flag;

	if (flag > 0)
	{
		player.SyncPlayer2MapByFlag(flag);
		msg_json["msgid"] = c_update_player_info;
		
		//m_msg_json_self["list"].append(msg_json);
		//m_msg_json_self["msgid"] = c_update_player_info;
		player.SendToClient(msg_json, c_update_player_info);
	}

	// 清除更新状态
	player.ClearUpdateInfoMyFlag();
}

void Player::SetThew(uint32_t thew)
{
	m_Thew = thew;
	Player::BroadcastSelfPlayer(*this, (uint32_t)UpdatePlayerInfoType::Vitality);
}

void Player::SetExps(uint32_t exps)
{
	m_Exps = exps;
	Player::BroadcastSelfPlayer(*this, (uint32_t)UpdatePlayerInfoType::Exp);
}

void Player::SetPetId(uint32_t pet_id)
{
	m_PetId = pet_id;
	Player::BroadcastSelfPlayer(*this, (uint32_t)UpdatePlayerInfoType::pet);
	SyncPlayer2MapByFlag((uint32_t)UpdatePlayerInfoType::pet);
}

void Player::SetMountsId(uint32_t val)
{
	m_MountsId = val;
	Player::BroadcastSelfPlayer(*this, (uint32_t)UpdatePlayerInfoType::mount);
	SyncPlayer2MapByFlag((uint32_t)UpdatePlayerInfoType::mount);
}

void Player::SetMountsState(uint32_t state)
{
	m_MountState = state;
	Player::BroadcastSelfPlayer(*this, (uint32_t)UpdatePlayerInfoType::mount);
	SyncPlayer2MapByFlag((uint32_t)UpdatePlayerInfoType::mount);
}